Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algolia Key Value Search

I am currently working with the Algolia search API and I am unable to figure out how I would limit the results by key value searching + query string. By this i mean this.

I have a list of properties. Each property belongs to a client.

Within the application If i am looking at a client information card and I want to search for a property that client owns It would make more sense to limit the results to the client and then look for the query string.

I am using MongoDB as my DB and storing the client id as a sub document like so

//Property Document
{
 _id : "randomID"
 client : {
  _id : "randomID",
  name : "ClientName"
 }
}
like image 454
Patrick Mencias-lewis Avatar asked May 25 '26 22:05

Patrick Mencias-lewis


1 Answers

If you want to restrict the search to a specific client, I would go for facet filtering to restrict the search to that client only.

  • Add client._id in the attributesForFaceting in your index settings
  • Filter your searches with the facetFilters=client._id:MYCLIENTID query parameter

Then, you should also take a look at the Secured API keys which are able to encode such restriction in a secure way (so the end-user cannot patch the JS code and work-around the filtering).

like image 157
redox Avatar answered May 28 '26 14:05

redox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!