Sunspot automaticly escape special characters -


using sunspot , solr 4+ there way automatically escape special characters.

for example in simple fulltext search like:

post.search   fulltext term end 

if term contains of special chars (http://lucene.apache.org/core/4_0_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#regexp_searches) should auto escaped.

inside initializers file add following code

re_escape_solr = /([-+!\(\)\{\}\[\]^"~*?:\\]|&&|\|\|)/  class string   def escape_solr     gsub(re_escape_solr) { |e| "\\#{e}" }   end end 

and whenever searching can call

post.search   fulltext term.escape_solr end 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -