sunspot_rails 编辑距离算子

发布于 11-24 17:49 字数 618 浏览 4 评论 0原文

我正在使用 sunspot_rails (在 Rails3 上)将我的 Rails 应用程序连接到 solr 服务器。我真的很想使用 ~ 运算符执行模糊搜索。无论如何,这似乎是不支持的。我现在重新使用 EdgeNGrams,但我对结果并不完全满意。

有什么建议吗?有人能够通过 sunspot_rails 进行 Levenshtein 距离搜索吗?

已解决

adjust_solr_params 方法Sunspot 提供的允许您覆盖默认的查询解析器,以便您可以使用支持 ~.基本上,我让 Sunspot 使用 lucene 查询解析器设置 defType 参数:

Post.search 做
   adjustment_solr_params 执行 |params|
       params[:q] = '字段名称:foo~'
       params[:defType] = 'lucene'
   结尾
结尾

I'm using sunspot_rails (on rails3) to interface my rails app to a solr server. I would really like to perform fuzzy searches using the ~ operator. Anyway it seems that this is not supported. I'm now falling back to use EdgeNGrams but I'm not completely satisfied by the results.

Any suggestion? Is anyone been able to make Levenshtein distance searches through sunspot_rails?

SOLVED

The adjust_solr_params method provided by Sunspot allow you to override the default query parser so you can use one that supports ~. Basically, I made Sunspot use the lucene query parser setting the defType pameter:

Post.search do
   adjust_solr_params do |params|
       params[:q] = 'field_name:foo~'
       params[:defType] = 'lucene'
   end
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文