1

我使用 Sphinx 在我的网络中进行搜索,但是当我使用 phpmyadmin 在 phpmyadmin 中搜索时,我有一件事

LIKE '%19.628%'

返回我正在寻找的数据(8 个匹配项),但是当我使用狮身人面像时返回更少的匹配项(3 个匹配项),相比之下 sql LIKE 搜索。

这里是 PHP 代码

$sp->SetMatchMode(SPH_MATCH_ANY);
$sp->SetArrayResult(true);
$sp->SetLimits(0,1000000);
$results = $sp->Query($query, 'data_base');

为什么?

问候

4

2 回答 2

1

Sphinx 不像 MySQL 那样使用通配符。以下是您可能无法获得想要的结果的几个原因;

  • 在您的示例中,MySQL 将评估该字段中的整个值。但是,Sphinx 对字符串的看法可能19.628有所不同。如果您使用默认的短语边界,那么 Sphinx 会将该字符串分解为 2 个单词,可能会导致不同的结果。

  • 的值究竟是$query多少?我怀疑它会类似于'* 19.628 *'。如果您没有启用星形语法,您可能无法获得您正在寻找的结果。

于 2013-08-31T18:07:43.757 回答
1

Remember that sphinx indexes whole words by default, so wont even get part-word matches unless explicitly enable it with infix/prefix indexing - with or without enable_star.

A sphinx query of 19.628 will just look for the whole words 19 and 628 anywhere in the document. Asumming . isn't in your charset_table of course!

In fact you even enable Any mode. So it looks for just one of the words.

So to get the same documents matching, would need to use Extended mode. Surround the query in " to get phrase matches. And use * in place of the %.

$cl->setMatchMode(SPH_MATCH_EXTENDED);
$cl->Query('"%19.628%"',$index);

For the index setting, you dont want . in phrase_boundary (because you want to use phrase searching), you need to enable part word matching - with min_infix_len, because want * at beginning and end of words (if using enable_star=1).

You can choose if you want . in charset_table or not. For this query it shouldn't matter much.

(tangental, but your really high $limit wont actully apply, setLimits has a third $max_matches param, which sets the highest $offset+$limit you can use - defaults to 1000)

于 2013-09-01T15:47:33.303 回答