【问题标题】:Algolia filter equivalent to SQL IN for arrays?Algolia 过滤器相当于数组的 SQL IN?
【发布时间】:2022-05-17 05:56:33
【问题描述】:

我在 Algolia 中有记录,其中包含具有整数值的数组属性,例如:

{
  ...
  choice_ids: [1, 99, 100, 200]
  ...
}

我想过滤包含另一个数组的任何值的所有记录。例如我搜索 [1, 300, 400, 600, 700],我应该得到最上面的记录,因为它包含 1。

我应该使用 OR 参数构造过滤器还是有更好的方法?

【问题讨论】:

    标签: algolia


    【解决方案1】:

    我应该使用 OR 参数构造过滤器还是有更好的方法?

    是的,这就是要走的路。

    index.search('....', { filters: '(choice_ids=1 OR choice_ids=99 OR choice_ids=100 OR choice_ids=200)' });
    

    【讨论】:

    • 这仍然是最好的方法吗?没有其他解决方案?
    • 是的,仍然是最好的方法。
    • 我们在过滤器中传递的值的总数是否有限制?
    【解决方案2】:

    对我来说,它不是使用 '=' 而是使用 ':',意思是:

    { filters: 'choice_ids:1 OR choice_ids:99 OR choice_ids:100 OR choice_ids:200' })
    

    【讨论】:

      【解决方案3】:

      对我来说,@Léo Chaz Maltrait 或 @redox 的答案都不起作用。我必须像这样格式化我的:

      { filters: '(choice_ids:"1") OR (choice_ids:"99" OR (choice_ids:"100") OR (choice_ids:"200"))' })
      

      我也在使用algoliasearch npm 包。

      【讨论】:

        猜你喜欢
        • 2019-04-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-03
        • 2012-02-11
        • 2012-03-10
        • 1970-01-01
        相关资源
        最近更新 更多