我有两个名为Products and Variants的模型,其中Variant模型具有关联性 产品作为产品有很多变种。变体模型的字段命名为 “available_on”...我想使用两个日期实现搜索,作为签到日期。
如果产品的变体可用于每个日期,签到日期到结帐日期,结果将映射所有这些产品,这是结果....
。 。 指导我如何使用Sunspot给出条件:solr
大致我的模型都是这样的
product
{
product_id integer
has_many variants
}
variant
{
variant_id integer
available_on date
belongs_to product
}
签到和结帐是搜索的输入。
答案 0 :(得分:0)
如果你对你的模型有疑问会更容易回答,但一般来说如果你有has_many关系而不是你应该索引嵌套模型
#variant model
searchable do
integer :product_id
time :check_in
time :check_out
end
如果您需要为父has_many
模型编制索引,可以这样使用:multiple=>true
选项
#product model
def variant_ids
variants.collect(&:id)
end
searchable do
integer :variant_ids, :multiple=>true
...
end
答案 1 :(得分:0)
为每个模型编制索引,并从SOLR返回所需的变体/产品。顺便说一下,如果你正在使用Spree,那么就有一个用于集成太阳黑子和狂欢的宝石。我只是分叉了它:https://github.com/banane/spree_sunspot_search