Thinking_sphinx“begins_with”询问

发布于 2024-11-09 04:08:04 字数 127 浏览 0 评论 0原文

我需要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 技术交流群。

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

发布评论

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

评论(1

蓬勃野心 2024-11-16 04:08:04

听起来您想要通配符搜索。要么将其添加到您的 config/sphinx.yml 文件中 - 或者创建它(如果您还没有):

development:
  enable_star: 1
  min_prefix_len: 1
# repeat for other environments

或者您可以将其放入特定索引中 - 因为中缀/前缀设置会增加戏剧性地改变你的索引:

define_index do
  # ...

  set_property :enable_star => 1
  set_property :min_prefix_len => 1
end

然后,运行 rake ts:rebuild 以便 Sphinx 知道这些更改并在索引中进行处理,然后你可以像这样搜索:

Student.search 'a*'
# or
Student.search :conditions => {:name => 'a*'}

如果你使用 min_infix_len 而不是min_prefix_len,您也可以匹配单词 - 即,将星号放在任一侧:

Student.search '*a*'

最后 - 如果您总是希望查询的每一端都有通配符星号每个术语,使用 :star =>; true 在您的搜索中:

Student.search 'a b c', :star => true
# is the same as
Student.search '*a* *b* *c*'

希望这可以帮助您获得您正在寻找的结果:)

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:

development:
  enable_star: 1
  min_prefix_len: 1
# repeat for other environments

Or you can put it in a specific index - as infix/prefix settings increase the size of your indices dramatically:

define_index do
  # ...

  set_property :enable_star => 1
  set_property :min_prefix_len => 1
end

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:

Student.search 'a*'
# or
Student.search :conditions => {:name => 'a*'}

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:

Student.search '*a*'

Finally - if you always want your queries to have wildcard stars on each end of every term, use :star => true in your searches:

Student.search 'a b c', :star => true
# is the same as
Student.search '*a* *b* *c*'

Hope this helps you get the result you're looking for :)

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