如何为思考狮身人面像的关键字添加权重

发布于 2024-12-19 19:08:18 字数 351 浏览 2 评论 0原文

我做了这样的搜索,

`  Comment.search "aabbb "`

我想得到也包含“ab”的结果。 所以我就这样做了:

`  Comment.search "aabbb ab"`

但是我发现结果aabbbab是混合的,事实上,我想让结果匹配aabbb显示在ab之前,换句话说,具有更高的优先级。

我知道狮身人面像可以增加表格字段的权重。例如,在评论名称中添加 10,在评论内容中添加 20。但是否可以增加查询工作的权重?

I did such search,

`  Comment.search "aabbb "`

and I want to get the results which contain "ab" too.;
So I did that way:

`  Comment.search "aabbb ab"`

but I found the results aabbb and ab are mixed , in fact, I want to make the results which match aabbb shows before ab, in other words, have a higher priority.

I know sphinx can add weight the fields of the table. for example add 10 to comments's name, 20 to comment's content. but is it possible to add weight to the query works?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

再浓的妆也掩不了殇 2024-12-26 19:08:18

不幸的是,这对于 sphinx 来说还不可能,但您可以通过多次添加您想要加权的关键字来在查询上添加类似的行为。

例如:

"aabbb | aabbb | ab"
The aabbb is twice more important than ab

Unfortunately this is not possible with sphinx yet but you can add similar behavior on a query by adding multiple times the keyword you want to weight.

For example:

"aabbb | aabbb | ab"
The aabbb is twice more important than ab
不必在意 2024-12-26 19:08:18

恐怕 Sphinx 无法对某些搜索短语进行加权 - 所以你想要做的事情是不可能的。

还值得注意的是,Sphinx 默认使用 AND 逻辑 - 如果您想要匹配 aabbb 或 ab 的结果,您可能需要使用 :any 匹配模式:

Comment.search "aabbb ab", :match_mode => :any

Sphinx has no ability to weight certain search phrases, I'm afraid - so what you're trying to do is not possible.

It's also worth noting that Sphinx uses AND logic by default - if you want results that match either aabbb OR ab, you'll probably want to use the :any match mode:

Comment.search "aabbb ab", :match_mode => :any
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文