1

I'm using sunspot to do fulltext searches in a customized spree webshop project.

There are Products, which are already extensively indexed:

class Product
  searchable do
    text :description
    ... lots of other declarations
  end
end

I now need to index Orders, which (via some other models, but I don't think this is important), have_many Products:

class Order
  has_many :products
end

The question is: I want Orders to be searchable via their products, using the same indexed attributes. I want to stay DRY and not add variations of the declarations on Product to a new searchable block on Order, but rather say something like "orders are searchable via products". Is this possible somehow ? The docs for sunspot don't mention anything like this.

EDIT:

"apneadiving" suggested putting the declarations in some sort of shared module and re-using it that way. I might be mistaken, but I think this can't work because the sunspot DSL refers to the current model, so the declarations from Product would not work on Order.

For example, if I could apply the searchable block from the example above in Order, it would instruct sunspot to index Order on description, which it doesn't have, and doesn't help me with indexing by products anyway.

Martin T.
  • 3,132
  • 1
  • 30
  • 31

0 Answers0