簡體   English   中英

使用Sunspot:solr搜索

[英]Search using Sunspot:solr

我有兩個模型,分別稱為“產品”和“變體”,其中“變體”模型與“產品”具有關聯,因為“產品”具有許多變體。 變量模型的字段名為“ available_on” ...我想使用兩個日期作為簽入n簽出日期來實現搜索。

如果某個產品的每個日期(從入住日期到結帳日期)都可用,結果將映射所有這些產品,這就是結果。

指導我如何使用Sunspot:solr給條件

我的模特大概是這樣的

product
{
product_id integer
has_many variants
}

variant
{
variant_id integer
available_on date
belongs_to product
}

簽入n簽出是搜索的輸入。

如果您對模型提出疑問,將更容易回答,但是如果您擁有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

索引每個模型,然后從SOLR返回您需要的變體/產品。 如果您正在使用Spree,那么有一個集成了w / sunspot和spree的寶藏。 我只是分叉了: https : //github.com/banane/spree_sunspot_search

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM