我在我的 Rails 3.1 环境中运行thinking-sphinx 2.0.10,索引和搜索工作得很好。当我在我的用户模型上搜索时,我想对用户名而不是电子邮件进行通配符搜索,因此只有在给定的搜索字符串与用户的电子邮件完全匹配时才应返回用户。我做了一些研究,发现这可以通过在 define_index 块中启用通配符搜索来完成
set_property :enable_star => true
set_property :min_infix_len => 1
并添加:infixes => true
到应该支持通配符搜索的索引
define_index do
indexes "CONCAT(first_name, ' ', last_name)", :as => :user_name, :infixes => true
indexes email
has :id, :as => :user_id
set_property :enable_star => true
set_property :min_infix_len => 1
end
这是来自自动生成的 development.sphinx.conf
index user_core
{
source = user_core_0
path = /../../../../db/sphinx/development/user_core
charset_type = utf-8
min_infix_len = 1
infix_fields = user_name
enable_star = 1
}
infix_fields
我猜是正确声明的。
问题是,如果我搜索“.com”,我仍然会得到所有具有 .com 电子邮件地址的用户。 这可能是什么原因?
谢谢你的帮助!