Thinking_sphinx“begins_with”询问
我需要thinking_sphinx查询来检索“begins_with”值。 意味着如果我给 Student.search 'a',我想显示所有名字以 a 开头的学生。 我已经对姓名字段建立了索引。现在,要检索学生,我必须给出确切的姓名。
I need thinking_sphinx query to retrieve "begins_with" values.
means if I give Student.search 'a', I want to display all student who have name starts with a.
I have indexed the name field already.Now, to retrieve a student, I have to give the exact name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您想要通配符搜索。要么将其添加到您的
config/sphinx.yml
文件中 - 或者创建它(如果您还没有):或者您可以将其放入特定索引中 - 因为中缀/前缀设置会增加戏剧性地改变你的索引:
然后,运行 rake ts:rebuild 以便 Sphinx 知道这些更改并在索引中进行处理,然后你可以像这样搜索:
如果你使用 min_infix_len 而不是min_prefix_len,您也可以匹配内单词 - 即,将星号放在任一侧:
最后 - 如果您总是希望查询的每一端都有通配符星号每个术语,使用
:star =>; true
在您的搜索中:希望这可以帮助您获得您正在寻找的结果:)
Sounds like you want wildcard searches. Either add this to your
config/sphinx.yml
file - or create it if you don't already have one:Or you can put it in a specific index - as infix/prefix settings increase the size of your indices dramatically:
And then, run
rake ts:rebuild
so the changes are known by Sphinx and processed in the indices, and then you can search like this:And if you use min_infix_len instead of min_prefix_len, you can match within words as well - that is, put the star on either side:
Finally - if you always want your queries to have wildcard stars on each end of every term, use
:star => true
in your searches:Hope this helps you get the result you're looking for :)