Algolia 首先搜索某个类别
Algolia search with a certain category first
我正在尝试搜索 Algolia 并让特定类别的结果显示在所有其他类别之前。这是一个例子:
Algolia 中的数据
{ name: Harry Potter, category: book},
{ name: The Avengers, category: movie},
{ name: Pottery, category: movie}
问题
假设正常的 Algolia 算法 Harry Potter
比电影 Pottery
更相关,所以通常如果您搜索 pot
,那么 Harry Potter
会出现在前面Pottery
.
我想将搜索词 pot
和类别 movie
传递给 Algolia,然后让 Pottery
显示在其他所有内容之前。它需要是动态的,即我应该能够搜索 pot
类别 book
并首先获得 Harry Potter
。
有没有办法用 Algolia 做到这一点?
实际上有一种很好的方法可以使用 "optional" facet 过滤器(即将发布的高级功能 - 截至 2016 年 12 月 1 日)来实现该行为。
"Optional Facet Filter" 是一个分面过滤器,它不需要匹配来检索结果,但默认情况下,它会确保首先检索具有分面值的命中(感谢 filters
Algolia 打破平局排名公式的标准。
这正是您想要的:在您希望首先检索共享 category
值的某些结果的每个页面上;只需使用 category:value
可选的分面过滤器查询 Algolia 索引。
- 确保您的
category
属性是 attributesForFacet
索引设置的一部分
- 在查询时,用
index.search('', { optionalFacetFilters: ["category:book"])
查询索引
您可以在 this (beta) documentation page 上阅读更多内容。
我正在尝试搜索 Algolia 并让特定类别的结果显示在所有其他类别之前。这是一个例子:
Algolia 中的数据
{ name: Harry Potter, category: book},
{ name: The Avengers, category: movie},
{ name: Pottery, category: movie}
问题
假设正常的 Algolia 算法 Harry Potter
比电影 Pottery
更相关,所以通常如果您搜索 pot
,那么 Harry Potter
会出现在前面Pottery
.
我想将搜索词 pot
和类别 movie
传递给 Algolia,然后让 Pottery
显示在其他所有内容之前。它需要是动态的,即我应该能够搜索 pot
类别 book
并首先获得 Harry Potter
。
有没有办法用 Algolia 做到这一点?
实际上有一种很好的方法可以使用 "optional" facet 过滤器(即将发布的高级功能 - 截至 2016 年 12 月 1 日)来实现该行为。
"Optional Facet Filter" 是一个分面过滤器,它不需要匹配来检索结果,但默认情况下,它会确保首先检索具有分面值的命中(感谢 filters
Algolia 打破平局排名公式的标准。
这正是您想要的:在您希望首先检索共享 category
值的某些结果的每个页面上;只需使用 category:value
可选的分面过滤器查询 Algolia 索引。
- 确保您的
category
属性是attributesForFacet
索引设置的一部分 - 在查询时,用
index.search('', { optionalFacetFilters: ["category:book"])
查询索引
您可以在 this (beta) documentation page 上阅读更多内容。