Hi all! I am attempting to add the ability to disa...
# community-help
c
Hi all! I am attempting to add the ability to disable searching certain types of documents, ie. Person A cannot search
type: [user]
, but they can search all other types (done so using the
additionalSearchParameters { filterBy }
. Is there a better way to do this? I am using NodeJS backend and the instantsearch adapter in the frontend.
f
c
So that works for most queries which is great, but I'm finding if I search with
*
or an empty space, the
filter_by
is no longer respected and all documents will be returned.
I tried a few other things but still getting the same issue, seems like whenever
q = "*"
the
filter_by
is not properly filtering by
type
how I have it defined, are you able to replicate this?
f
This shouldn't be the case. Either the API key isn't properly defined or something else. Did you create the the API keys using the JS sdk?
c
Yep, created a scoped API key with the SDK
f
Could you point me to some reproduction steps so I can debug it myself?
c
Yep! This is how it is currently being used using the JS SDK
Copy code
await SearchClient.collections(collection_id).documents().search({
  // NOTE: The colleciton usually includes entityD as well, but we don't want to search for it.
  // So we are omitting it from the filter_by types, the query_by fields, and the include_fields.
  
  // If I search for entityD.name directly (instead of q = "*"), it will return an empty array and
  // no hits will be found (as expected), but if I search for q = "*", it will return all the hits
  // including any hits for entityD. This is not the expected behavior.
  q: "*",
  filter_by: "accessibleTo: [<some_ids>], type: [entityA, entityB, entityC]",
  query_by: "entityA.name, entityB.name, entityC.name",
  include_fields: "id, type, entityA.name, entityB.name, entityC.name",
})
Ah i think it was user error on my end...my
filter_by
field was not using the right multiple conditions operator 🤦 , was using
filter_by: "accessibleTo: [], type: []
rather than
filter_by: "accessibleTo: [] && type: []
Looks like it is working as expected! ty!