简体   繁体   English

使用Sunspot:solr搜索

[英]Search using Sunspot:solr

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. 变量模型的字段名为“ available_on” ...我想使用两个日期作为签入n签出日期来实现搜索。

.

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 指导我如何使用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. 签入n签出是搜索的输入。

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 如果您对模型提出疑问,将更容易回答,但是如果您拥有has_many关系,则通常比索引嵌套模型要容易

#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 如果您需要从父has_many模型中索引某些内容,可以使用:multiple=>true选项以这种方式

#product model

def variant_ids     
  variants.collect(&:id)
end

searchable do

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

end

Index each model, and return the variant/product you need from SOLR. 索引每个模型,然后从SOLR返回您需要的变体/产品。 If you're using Spree by the way, there's a gem for integrating w/ sunspot and spree. 如果您正在使用Spree,那么有一个集成了w / sunspot和spree的宝藏。 I just forked it: https://github.com/banane/spree_sunspot_search 我只是分叉了: https : //github.com/banane/spree_sunspot_search

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM