【发布时间】:2022-05-17 05:56:33
【问题描述】:
我在 Algolia 中有记录,其中包含具有整数值的数组属性,例如:
{
...
choice_ids: [1, 99, 100, 200]
...
}
我想过滤包含另一个数组的任何值的所有记录。例如我搜索 [1, 300, 400, 600, 700],我应该得到最上面的记录,因为它包含 1。
我应该使用 OR 参数构造过滤器还是有更好的方法?
【问题讨论】:
标签: algolia
我在 Algolia 中有记录,其中包含具有整数值的数组属性,例如:
{
...
choice_ids: [1, 99, 100, 200]
...
}
我想过滤包含另一个数组的任何值的所有记录。例如我搜索 [1, 300, 400, 600, 700],我应该得到最上面的记录,因为它包含 1。
我应该使用 OR 参数构造过滤器还是有更好的方法?
【问题讨论】:
标签: algolia
我应该使用 OR 参数构造过滤器还是有更好的方法?
是的,这就是要走的路。
index.search('....', { filters: '(choice_ids=1 OR choice_ids=99 OR choice_ids=100 OR choice_ids=200)' });
【讨论】:
对我来说,它不是使用 '=' 而是使用 ':',意思是:
{ filters: 'choice_ids:1 OR choice_ids:99 OR choice_ids:100 OR choice_ids:200' })
【讨论】:
对我来说,@Léo Chaz Maltrait 或 @redox 的答案都不起作用。我必须像这样格式化我的:
{ filters: '(choice_ids:"1") OR (choice_ids:"99" OR (choice_ids:"100") OR (choice_ids:"200"))' })
我也在使用algoliasearch npm 包。
【讨论】: