狮身人面像 + php,查询结果意外的问题

发布于 2024-11-25 05:06:07 字数 1562 浏览 1 评论 0原文

我正在开发一个启用 sphinx (php) 的自动完成字段,该字段可以查找用户。我遇到了一些奇怪的情况,其中某些应该返回匹配项的输入却没有返回匹配项。

我的用户索引中的字段是:

'fullname',
'username',
'address',
'phone',
'email'

一些常规配置信息:

charset_type = utf-8
enable_star    = 1
min_infix_len  = 3
ignore_chars = U+20

我当前的查询设置如下:

$search = preg_replace('/([^\s]{3,})/', '*$1*', preg_replace('/[^a-z ]/i', '', $search));
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$matches = $sphinx->Query($search . ' @email company.com', 'users');

问题伴随以下搜索参数:

John -> returns list of all Johns (GOOD!)
John S -> returns nothing (BAD!)
John St -> returns all John St*'s (GOOD!)

同样:

Ben -> returns all Ben's (GOOD!)
Ben M -> returns nothing (BAD!)
Ben Ma -> returns nothing (BAD!)
Ben Mar -> returns user with Ben Mar*'s (GOOD!)

最初我认为问题是因为名字和姓氏位于不同的字段中索引,但现在我已将它们合并到全名字段中,我仍然得到完全相同的结果。

目前(通过上面的 preg_replace)我正在将输入的每个单词包装在 * 中。我也尝试过用 * 包裹整个字符串,

$search = '*' . $search . '*';

但结果不太准确。我尝试过extended2之外的其他搜索模式,但没有成功。 (情况变得更糟)我添加了一个选项来忽略配置中的空格,希望它能更好地选择“John S”之类的东西,但仍然没有运气。

大多数情况下,我只是希望人们能够通过输入名字+姓氏首字母来找到用户。这是人们尝试查找用户名的常见方式,但目前还不能。

非常感谢任何帮助。谢谢!

编辑:

在大量搜索中我发现了这个:http://sphinxsearch.com/forum/view。 html?id=5757

似乎在使用空格搜索时可能存在一些错误/不一致。但如果有人有任何想法请评论。谢谢!

I'm working on a sphinx (php) enabled autocomplete field that does a look up of users. I'm running into some odd situations where certain inputs which should return matches do not.

The fields in my users index are:

'fullname',
'username',
'address',
'phone',
'email'

Some general config info:

charset_type = utf-8
enable_star    = 1
min_infix_len  = 3
ignore_chars = U+20

My current query is set up as follows:

$search = preg_replace('/([^\s]{3,})/', '*$1*', preg_replace('/[^a-z ]/i', '', $search));
$sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
$sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$matches = $sphinx->Query($search . ' @email company.com', 'users');

The issue comes with with the following search params:

John -> returns list of all Johns (GOOD!)
John S -> returns nothing (BAD!)
John St -> returns all John St*'s (GOOD!)

Similarly:

Ben -> returns all Ben's (GOOD!)
Ben M -> returns nothing (BAD!)
Ben Ma -> returns nothing (BAD!)
Ben Mar -> returns user with Ben Mar*'s (GOOD!)

Originally I thought the problem was because firstname and lastname were in different fields of the index, but now that I've merged them into the fullname field and I still get the exact same results.

Currently (via above preg_replace) I'm wrapping each word entered in *'s. I've also tried just wrapping the entire string with *,

$search = '*' . $search . '*';

but with less accurate results. I've tried the other search modes besides extended2 with no luck. (It just gets worse) I added a option to ignore spaces in the config, hoping it would pick on things like "John S" better, but still no luck.

Mostly I'd just like for people to be able to find a user by typing in First name + last initial. It's a common way people try to look up usernames, and currently they can't.

Any help is very appreciated. Thanks!

EDIT:

In much searching I found this: http://sphinxsearch.com/forum/view.html?id=5757

It seems there may be some bugs/inconsistencies in searching with spaces. But if anyone has any ideas please comment. Thanks!

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

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

发布评论

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

评论(1

耀眼的星火 2024-12-02 05:06:07

打开部分索引。

环顾四周:
最小中缀长度
最小前缀长度

Turn on partial indexing.

Look around:
min_infix_len
min_prefix_len

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