使用Algolia的数值滤波器时如何使用AND和OR

时间:2015-08-06 09:25:32

标签: algolia

考虑一个填充了这样的对象的Algolia索引:

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

此查询是否获得具有contributor_ids 42或contributor_ids = 12的所有对象?

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

如果是这样,获得所有具有contributor_ids 42和contributor_ids = 12的对象的正确查询是什么?

1 个答案:

答案 0 :(得分:9)

默认行为是AND,您可以使用带括号的OR:

numericFilters: "contributor_ids=42, contributor_ids=12"

表示contributor_ids = 42 AND contributor_ids = 12,只有在包含两个值的记录时才匹配

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

表示contributor_ids = 42或contributor_ids = 12

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

表示contributor_ids = 10 AND(contributor_ids = 42或contributor_ids = 12)