quinta-feira, 2 de fevereiro de 2012

Having trouble with rails sunspot and tomcat solr using utf-8 searches?

If after setting tomcat Connector using URIEncoding="UTF-8" didn't work, try this in rails application:

create a file like this name:
config/initializers/monkey_patch_sunspot_solr.rb

Put this code:
module Sunspot
module Search
class AbstractSearch
# Fix utf-8 trouble in search with solr, tomcat and sunspot_solr by Klaus Magalhaes
def execute
reset
params = @query.to_params
save_ferris = {:data => params, :headers => {'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'}}
@solr_result = @connection.post "#{request_handler}", save_ferris
self
end
end
end
end

restart the rails application and cross your fingers...