Question

I have two models, named as Products and Variants, in which Variant model have association with Products as a Product have many Variants. Variant model have field named as "available_on" ... I want to implement search using two dates as check-in n checkout dates.

.

if variants for a product available for each date , check-in date to checkout date, result will map all those products and it is the result....

. . guide me how i should give conditions using Sunspot:solr

roughly my models are like this

product
{
product_id integer
has_many variants
}

variant
{
variant_id integer
available_on date
belongs_to product
}

check-in n checkout are the inputs for the search.

Was it helpful?

Solution

it will be easier to answer if you put your models in question but in general way if you have has_many relationship than you should index nested model

#variant model

searchable do

  integer :product_id
  time :check_in     
  time :check_out     

end

if you need to index something from parent has_many model you can use :multiple=>true option in this way

#product model

def variant_ids     
  variants.collect(&:id)
end

searchable do

  integer :variant_ids, :multiple=>true
  ...

end

OTHER TIPS

Index each model, and return the variant/product you need from SOLR. If you're using Spree by the way, there's a gem for integrating w/ sunspot and spree. I just forked it: https://github.com/banane/spree_sunspot_search

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top