Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sunspot - solr - How to do Exact match

articles = Article.search do |s|
    s.fulltext "Java Script"
end

How do i tell sunspot like give me all the results which exactly matches "Java Script" Right now am getting results like "Java, Unix Scripting" (I think its the edge n gram which i am using for stemming takes this scripting results)

I found a couple of questions in stack overflow . unfortunately, no body answered the way i want. Hence i am posting this question here. I request the moderators not to mark it as duplicate

like image 589
Krishna Prasad Varma Avatar asked Aug 17 '12 13:08

Krishna Prasad Varma


1 Answers

Here is what you can add to your controller to make "Quoted Values" return an exact match.

  @search = Program.search do
     fulltext params[:search].gsub( '"', '"\\' ) unless params[:search].blank? 
     //...
  end

If you had text like this that is being searched...

the fox jumped over the tree
  • Search for fox over would return 1 row.

  • However a search for "fox over" (in quotes) would return 0 rows.

  • Search for "fox jumped" (also in quotes) would return 1 rows. This is the exact match.

like image 137
dsmithco Avatar answered Sep 27 '22 23:09

dsmithco