Algolia 先用某个类别搜索 [英] Algolia search with a certain category first

查看:21
本文介绍了Algolia 先用某个类别搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试搜索 Algolia,并且某个类别的结果显示在所有其他类别之前.举个例子:

I'm trying to search Algolia and have results for a certain category show up before all other categories. Here's an example:

Algolia 中的数据

{ name: Harry Potter, category: book},
{ name: The Avengers, category: movie},
{ name: Pottery, category: movie}

问题

假设普通的 Algolia 算法具有 Harry Potter 比电影 Pottery 更相关的方式,所以通常如果你搜索 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.

我想向 Algolia 传递搜索词 pot 和类别 movie,然后让 Pottery 显示在其他所有内容之前.它需要是动态的,即我应该能够搜索 pot 类别为 book 并首先获得 Harry Potter.

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.

有没有办法用 Algolia 做到这一点?

Is there a way to do this with Algolia?

推荐答案

实际上有一种很好的方法可以使用可选"方面过滤器来实现该行为(即将发布的高级功能 - 截至 2016/12/01).

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.

  • 确保您的 category 属性是您的 attributesForFacet 索引设置的一部分
  • 查询时,用index.search('', { optionalFacetFilters: ["category:book"])
  • 查询索引
  • make sure your category attribute is part of your attributesForFacet index setting
  • at query time, query the index with index.search('', { optionalFacetFilters: ["category:book"])

您可以在此(测试版)文档页面上阅读更多信息.

You can read more on this (beta) documentation page.

这篇关于Algolia 先用某个类别搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆