Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sunspot solr search by multiple terms

I am using the sunspot_rails gem, and I am trying to do a search like:

search users where name is Mary or Sally

But I can't figure out how to do the or. If I do something like:

search = Users.search do
  fulltext 'Mary Sally'
end

or

search = Users.search do
  fulltext 'Mary'
  fulltext 'Sally'
end

I get no results...but if I do either one, and not both, I get the expected results:

search = Users.search do
  fulltext 'Mary' #or fulltext 'Sally'
end

will return the single item.

Is this even possible with sunspot?

-------Solution-------

search = Users.search do
  fulltext 'Mary Sally' do
    minimum_match 1
  end
end
like image 589
Toadums Avatar asked Oct 05 '13 19:10

Toadums


1 Answers

Add minimum_match 1 to your search block because default setting is to match all words, so searching for Mary Sally would return records only with those both names included.

like image 171
zrl3dx Avatar answered Oct 17 '22 11:10

zrl3dx