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

Capture and play voice with Asterisk ARI -

java - Why database contraints in HSQLDB are only checked during a commit when using transactions in Hibernate? -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -