如何为sphinx查询设置更具体的规则?

发布于 2024-11-28 19:20:34 字数 478 浏览 1 评论 0原文

我有一个包含电影和电视剧列表的数据库。 我构建的搜索使用 Sphinx。

我使用 SPH_MATCH_ANY 模式,因为我希望如果一个人搜索“x-men 2”,他也会找到有关“x-men 1”和“x-men 3”的条目。

我的问题是,它还会搜索带有“2”的条目,例如“汽车总动员 2”或“超自然季节 2”。

我想告诉它不要搜索其中没有“x-men”的条目。 在 MYSQL 中我会这样写:

MATCH (mname) AGAINST ('x-men') AND mname like '%x-men%' 

或类似的东西。

在Sphinx中我尝试了这个:

$s->Query(x-men 2 "x-men",'test1');

但它仍然搜索其中包含数字“2”的条目..

那么我怎样才能做到这一点呢?

谢谢。

I have a database with list of movies and tv series.
The search I built uses Sphinx.

I use SPH_MATCH_ANY mode, because I want that if a person search for "x-men 2" he will also find entries about "x-men 1" and "x-men 3".

My problem is, it also searches for entries with "2", for example "Cars 2", or "Supernatural season 2".

I want to tell it not to search entries that have no 'x-men" in them.
In MYSQL I would write it like this:

MATCH (mname) AGAINST ('x-men') AND mname like '%x-men%' 

or something like that.

In Sphinx I tried this:

$s->Query(x-men 2 "x-men",'test1');

But It still searched for entries with the number "2" in them..

So how can I accomplish that?

Thank you.

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

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

发布评论

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

评论(2

温柔少女心 2024-12-05 19:20:34

好的问题解决了,Sphinx 论坛的一个人给了我这个解决方案:

$s->setMatchMode(SPH_MATCH_EXTENDED2);
$s->Query("(x-men | 2) x-men",test1);
$s->setRankingMode(SPH_RANK_ANY);

=)

Ok problem solved, a guy from Sphinx forum gave me this solution:

$s->setMatchMode(SPH_MATCH_EXTENDED2);
$s->Query("(x-men | 2) x-men",test1);
$s->setRankingMode(SPH_RANK_ANY);

=)

初雪 2024-12-05 19:20:34

你需要像计算机一样思考......对我们来说,很明显“x战警”这个词比“2”更相关,但对于计算机来说它们都是平等的。

您可以随时告诉 sphinx 将“x-men 1”、“x-men 2”和“x-men 3”索引到同一索引,使用 wordforms

x-men 1 > xmen
x-men 2 > xmen
x-men 3 > xmen

因此,如果有人搜索“x-men 2”,他将看到这 3 部电影的结果。或者您可以告诉 sphinx 不要索引单个数字,或设置 索引的最小长度

但用户可能会抱怨他们只想看《X战警2》的信息,而不是其他电影。

在我看来,在配置搜索引擎时,您不必猜测用户想要的结果,因为不同的用户会期望不同的结果,但您应该始终为他提供工具来完善他的搜索结果搜索。例如,一个人会期望 x-men 2 返回所有 x-men 电影,另一个人会期望它返回仅与 x-men 2 相关的信息,并且(为什么不呢?)有人会期望它返回所有包含“x战警”和“2”字样的电影......你不能让每个人都高兴=P

祝你好运

You need to think like a computer... for us is quite obvious that the word "x-men" is more relevant than "2", but for a computer they are both equal.

You could always tell sphinx to index "x-men 1","x-men 2" and "x-men 3" to the same index, using the wordforms

x-men 1 > xmen
x-men 2 > xmen
x-men 3 > xmen

so if someone searches for "x-men 2" he will see the results for the 3 movies. Or you could tell sphinx not to index single numbers, or set the min length for indexes.

But then the users might complain that they wanted ONLY to see the info of "x-men 2" and not the other movies.

In my opinion, when configuring a search engine you don't have to guess what the user wants as a result, because different users will expect different results, but you should always give him the tools to refine his search. For example, one person would expect that x-men 2 returns all x-men movies, another person would expect it to return info related only to x-men 2, and (why not?) someone will expect it to return all movies containing the words "x-men" and "2"... you can't make everybody happy =P

Good Luck

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