开发者

sunspot_rails Levenshtein distance operator

开发者 https://www.devze.com 2023-03-21 00:14 出处:网络
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 s

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
0

精彩评论

暂无评论...
验证码 换一张
取 消