Reputation: 1574
I have the Rails project with User model.
It has two fields: :name
, :surname
Also I have sunset search:
searchable do
text :name
text :surname
end
When I do such search:
User.solr_search { fulltext 'Name Surname' } .results
how to get results all results in such order:
'Name Surname'
'Surname'
'Name'
Also I found, but I don't understand is that what I need https://github.com/sunspot/sunspot/wiki/Matching-substrings-in-fulltext-search
Upvotes: 0
Views: 104
Reputation: 5740
You can use boosters, so that surname results come before name results and surname&name results before surname results.
searchable do
text :surname, boost: 2.0
text :name, boost: 1.0
end
You ask any term to be matched and then order them descendingly on score. Results matching name and surname will score higher, only surname lower and only name lowest.
@search=User.search
fulltext "#{name_variable} #{surname_variable}", :minimum_match => 1
order_by(:score, :desc)
end
Upvotes: 1