ThinkingSphinx 匹配确切的短语
我使用 Sphinx 和 ThinkingSphinx gem 与 Rails 3 进行搜索。我想搜索 sphinx 索引列的某个字符串的精确匹配,但似乎没有好的方法可以做到这一点。根据 ThinkingSphinx 文档,匹配模式为 :any、:phrase、:all,但它们似乎都在子字符串上搜索。例如,搜索“1997”也将与“1997 Honda”或“1997 Ford”匹配。在我的情况下,我想搜索“1997”的精确匹配,因此“1997 Honda”和“1997 Ford”不应该匹配。这对于 MySQL 来说很简单,但我还没有找到一种方法来做到这一点。
谢谢!
I'm using Sphinx and ThinkingSphinx gem with Rails 3 for searching. I want to search for exact match of a certain string for an sphinx-indexed column but there seems to be no good way to do so. According to ThinkingSphinx documentation, the matching modes are :any, :phrase, :all, but they all seem to search on substring. For example, searching for "1997" will also match with "1997 Honda", or "1997 Ford". In my situation, I want to search for the exact match of "1997", thus "1997 Honda" and "1997 Ford" should not match. This is straightforward with MySQL, but I have not found a way to do so.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Sphinx 在 0.9.9-rc2 版本中引入了字段开始和字段结束运算符。
要使用您的示例,您将搜索“^1997$”
Sphinx introduced the field-start and field-end operators in version 0.9.9-rc2.
To use your example, you would search for '^1997$'