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?
search = Users.search do
fulltext 'Mary Sally' do
minimum_match 1
end
end
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With