Krishna Prasad Varma
Krishna Prasad Varma

Reputation: 4740

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

Upvotes: 11

Views: 1610

Answers (1)

dsmithco
dsmithco

Reputation: 361

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.

Upvotes: 5

Related Questions