Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AND and OR when using Algolia's numerical filter

Tags:

algolia

Consider an Algolia index filled with objects like this:

{ 
   "objectID": 1, 
   "name": "My project title", 
   "contributor_ids": [12, 42, 34] 
} 

Does this query get all objects that have contributor_ids 42 OR contributor_ids=12 ?

"numericFilters: 'contributor_ids=42, contributor_ids=12" 

And if so, what is the right query to get all objects that have contributor_ids 42 AND contributor_ids=12 ?

like image 762
murze Avatar asked Jan 07 '23 19:01

murze


1 Answers

The default behavior is a AND, you can have a OR with parenthesis:

numericFilters: "contributor_ids=42, contributor_ids=12"

Means contributor_ids=42 AND contributor_ids=12, only match if you have a record containing both values

numericFilters: "(contributor_ids=42, contributor_ids=12)"

Means contributor_ids=42 OR contributor_ids=12

numericFilters: "contributor_ids=10,(contributor_ids=42, contributor_ids=12)"

Means contributor_ids=10 AND (contributor_ids=42 OR contributor_ids=12)

like image 192
speedblue Avatar answered Jan 10 '23 07:01

speedblue