首先搜索特定类别的阿尔及利亚 [英] Algolia search with a certain category first
问题描述
我正尝试搜索Algolia,并在所有其他类别之前显示特定类别的结果。例如:
I'm trying to search Algolia and have results for a certain category show up before all other categories. Here's an example:
阿尔及利亚的数据
{ name: Harry Potter, category: book},
{ name: The Avengers, category: movie},
{ name: Pottery, category: movie}
问题
比方说正常的Algolia算法与电影陶器
相比,哈利·波特
的相关性更高,因此通常如果您搜索 pot
,然后 Harry Potter
将出现在 Pottery
之前。
Let's say the normal Algolia algorithm has Harry Potter
way more relevant than the movie Pottery
, so normally if you searched pot
then Harry Potter
would show up ahead of Pottery
.
我想将搜索词 pot
和类别 movie
传递给Algolia,然后将陶器
首先出现。它必须是动态的,即我应该能够搜索类别为 book
的 pot
并获得首先是哈利·波特
。
I want to pass Algolia the search term pot
and the category movie
and then have Pottery
show up ahead of everything else. It needs to be dynamic, i.e. I should be able to search pot
with category book
and get Harry Potter
first.
阿尔戈利亚有办法做到这一点吗?
Is there a way to do this with Algolia?
推荐答案
实际上,有一种很好的方法可以使用可选构面过滤器来实现该行为(即将发布的高级功能-截至2016年12月1日)。
There is actually a nice way to implement that behavior using "optional" facet filters (a soon to be released advanced feature - as of 2016/12/01).
可选方面过滤器是不需要进行匹配以检索结果的方面过滤器,但是-默认值-确保首先检索具有构面值的匹配(这要感谢Algolia抢七式排名公式的过滤器
标准)。
An "Optional Facet Filter" is a facet filter that doesn't need to match to retrieve a result but that will - by default - make sure the hits that have the facet value are retrieved first (thanks to the filters
criterion of Algolia's tie-breaking ranking formula).
这正是您想要的:在每个页面上,您需要首先获取共享 category
值的某些结果;只需使用 category:value
可选构面过滤器查询Algolia索引即可。
This is exactly what you want: on every single page where you want some results sharing a category
value to be retrieved first; just query the Algolia index with the category:value
optional facet filter.
- make确保您的
类别
属性是查询中attributesForFacet
索引设置 - 的一部分时间,请使用
index.search('',{optionalFacetFilters:[ category:book])
- make sure your
category
attribute is part of yourattributesForFacet
index setting - at query time, query the index with
index.search('', { optionalFacetFilters: ["category:book"])
您可以在此(测试版)文档页面。
这篇关于首先搜索特定类别的阿尔及利亚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!