Question

I have 3 classes, Products, Reviews, Categories. When someone searches, I would like the categories to show up first, then Reviews, then Categories. My first thought is to boost the score of each class. The sunspot documentation describes how to do this

Sunspot.setup(Review) do
    boost 1.2
end

but I have no idea where to put this and I'd need to do it for each class.

Was it helpful?

Solution

This should go into your index declaration, as you don't need to do it in query time. For example:

class Product < ActiveRecord::Base
  seachable do
    text :title
    boost 1.3
  end
end

class Review < ActiveRecord::Base
  seachable do
    text :author
    boost 1.2
  end
end

class Category < ActiveRecord::Base
  seachable do
    text :name
    boost 1.1
  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top