Algolia:使用可能值的字符串数组按字符串数组属性过滤索引
Algolia: Filter Index by string array attribute with a string array of possible values
我有一个包含如下对象的 Algolia 索引:
id: 2,
name: test,
important: ["lorem", "ipsum", "dolor", "sit", "amet"]
我想检索所有条目,例如包含 "dolor"
或 "sit"
。
我该怎么做?
注意:这只是一个示例,每个条目的 important
数组通常包含大约 1 到 4 个值(总共大约 1.000 个可能的值)。按 / 搜索以过滤它的数组可以包含 1 到 400 个值之间的任何值。
什么 AFAIK 不起作用:
使用 facetQuery 在构面值中搜索:facetQuery 不允许布尔运算符。因此我一次只能搜索 "dolor"
或 "sit"
之一,参见 docs。
然而 filters docs 说
Non-numeric attributes (e.g. strings) need to be set up as categories, which we call facets.
所以我想知道这是否可能...?或者也许我以错误的方式处理这个问题?
您找对地方了,需要组合 attributesForFaceting 和过滤器:
- 通过 API 或仪表板将
important
属性设置为 attributesForFaceting
- 然后使用 filters 筛选您想要的值
您的过滤器将如下所示:{ "filters": "important:dolor OR important:sit" }
我有一个包含如下对象的 Algolia 索引:
id: 2,
name: test,
important: ["lorem", "ipsum", "dolor", "sit", "amet"]
我想检索所有条目,例如包含 "dolor"
或 "sit"
。
我该怎么做?
注意:这只是一个示例,每个条目的 important
数组通常包含大约 1 到 4 个值(总共大约 1.000 个可能的值)。按 / 搜索以过滤它的数组可以包含 1 到 400 个值之间的任何值。
什么 AFAIK 不起作用:
使用 facetQuery 在构面值中搜索:facetQuery 不允许布尔运算符。因此我一次只能搜索
"dolor"
或"sit"
之一,参见 docs。然而 filters docs 说
Non-numeric attributes (e.g. strings) need to be set up as categories, which we call facets.
所以我想知道这是否可能...?或者也许我以错误的方式处理这个问题?
您找对地方了,需要组合 attributesForFaceting 和过滤器:
- 通过 API 或仪表板将
important
属性设置为 attributesForFaceting- 然后使用 filters 筛选您想要的值
您的过滤器将如下所示:{ "filters": "important:dolor OR important:sit" }