使用 Sphinx 搜索多列
我有带有列的模型产品:
name, number, description
为此模型定义的索引如下所示:
define_index do
indexes :name, :sortable => true
indexes :number
indexes :description
where "amount > 0"
has :price
end
由于描述中可能有很多随机单词,我有时想将其从搜索中排除(当用户单击复选框“不在描述中搜索”时)。
我访问了 sphinx 页面并发现了以下内容:
@(name, number) *pencil* *123*
看来我不明白 sphinx 是如何工作的。当我执行搜索时,
*pencil* *123*
在名称中找到“铅笔”,在数字中找到“123”,我得到 1 个结果。但是当我执行时
@(name, number) *pencil* *123*
没有找到结果。
按列搜索是否有所不同?
I have model Products with columns:
name, number, description
Index defined for this model looks like this:
define_index do
indexes :name, :sortable => true
indexes :number
indexes :description
where "amount > 0"
has :price
end
Since in description can be lots of random words I want to exclude it from searching sometimes (when user clicks chceckbox 'don't search in descriptions').
I went to the sphinx page and found following:
@(name, number) *pencil* *123*
And it seems like I don't understand how sphinx works. When I execute search
*pencil* *123*
word 'pencil' is found in name and '123' is found in number and I get 1 result. But when I execute
@(name, number) *pencil* *123*
no results are found.
Is searching by columns somehow different?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只能在使用
:extended
匹配模式时搜索字段 - 如果您使用:conditions
,Thinking Sphinx 会自动设置此模式 - 但您要自己构建多字段查询,这就是为什么这没有发生。试试这个:希望这有帮助。
You can only search on fields when using the
:extended
match mode - Thinking Sphinx sets this automatically if you use:conditions
- but you're constructing a multi-field query yourself, hence why this isn't happening. Try this:Hope this helps.
这都是关于空间的:/
这有效:
It was all about spaces :/
This works: