简体   繁体   English

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

[英]How do I set more specific rules for sphinx query?

I have a database with list of movies and tv series.我有一个包含电影和电视剧列表的数据库。 The search I built uses Sphinx.我建立的搜索使用 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".我使用 SPH_MATCH_ANY 模式,因为我希望如果一个人搜索“x-men 2”,他也会找到有关“x-men 1”和“x-men 3”的条目。

My problem is, it also searches for entries with "2", for example "Cars 2", or "Supernatural season 2".我的问题是,它还会搜索带有“2”的条目,例如“Cars 2”或“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:我想告诉它不要搜索其中没有“x-men”的条目。在 MYSQL 我会这样写:

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..但它仍然搜索其中带有数字“2”的条目..

So how can I accomplish that?那么我该如何实现呢?

Thank you.谢谢你。

Ok problem solved, a guy from Sphinx forum gave me this solution:好的问题解决了,Sphinx论坛的一个人给了我这个解决方案:

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

=) =)

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.你需要像电脑一样思考……对我们来说很明显,“x-men”这个词比“2”更相关,但对于电脑来说,它们都是平等的。

You could always tell sphinx to index "x-men 1","x-men 2" and "x-men 3" to the same index, using the wordforms您总是可以告诉 sphinx 使用wordforms将“x-men 1”、“x-men 2”和“x-men 3”索引到同一个索引

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.因此,如果有人搜索“x-men 2”,他将看到 3 部电影的结果。 Or you could tell sphinx not to index single numbers, or set the min length for indexes .或者你可以告诉 sphinx 不要索引单个数字,或者设置索引的最小长度

But then the users might complain that they wanted ONLY to see the info of "x-men 2" and not the other movies.但随后用户可能会抱怨他们只想看到“x-men 2”的信息,而不是其他电影。

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例如,一个人会期望x-men 2返回所有 x-men 电影,另一个人会期望它返回仅与 x-men 2 相关的信息,并且(为什么不呢?)有人会期望它返回所有包含“x战警”和“2”这两个词……你不能让每个人都开心=P

Good Luck祝你好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM