ranking or boosting results

12 views
Skip to first unread message

ticcoid

unread,
May 23, 2013, 1:58:19 PM5/23/13
to ruby-s...@googlegroups.com
Hi,

I have a very common problem which should be normally already solved by someone, but even after days of researching I couldnt find any solutions.
Here is the problem I'm trying to solve:

I have two models

Destination
has_many :interests

Interest
belongs_to :destination

The interest model has a name and a score. So I could have the following setup:

A destination "miami" which has an interest "beach" of score "9"
A destination "New York" which has an interest "beach" of score "6"


In the destination model I setup the sunspot searchable block something like this:

searchable :auto_index => true, :auto_remove => true do
   integer :interest_ids, :multiple => true do
      index_interest_ids
    end
end

def index_interest_ids
  interests.map do |interest|
    if interest.score > 5
      interest.id
    end
  end
end


So far so good. When I now do a sunspot search for beach it brings me back all the destination which have an interest of beach scored higher than 5. But now I would like to rank the results based on the score. So when I search for beach, Miami should ranked higher than New York. 

Anybody an idea how this could work?
Reply all
Reply to author
Forward
0 new messages