弹性搜索相当于太阳黑子/ solr中的“范围(标量字段)”

时间:2013-01-29 09:19:57

标签: solr elasticsearch sunspot tire

我正在为我们的rails-app / data探索搜索引擎的各种选项。我能够制作太阳黑子/ solr工作,目前正在探索ElasticSearch作为替代方案,但无法在ES下工作(范围/过滤)。

我想过滤/范围对象,如“https://github.com/sunspot/sunspot”中的“范围”部分所述。

我有一个活跃的唱片类'产品'。

class Product < ActiveRecord::Base
...

  include Tire::Model::Search
  include Tire::Model::Callbacks

  tire.mapping do
    indexes :name, :type => :string
    indexes :categories do
      indexes :id, :type => :integer
    end
  end
end

将产品导入ES后,

以下查询有效并提供结果

Product.tire.search { query { string '*', default_operator: "AND", default_field: "name" } }.results

如何根据类别ID获取特定类别的产品?

Product.tire.search { query { string '*', default_operator: "AND", default_field: "name" }; filter(:term, 'categories.id' => 38) }.results

我基本上在寻找以下太阳黑子电话的轮胎等价物:

Product.search do
  with(:category_ids, 38)
end

在Product类中使用以下内容

searchable :auto_index => true, :auto_remove => true do
  text :name

  integer :category_ids, :multiple => true do
     self.categories.map &:id
  end

end

0 个答案:

没有答案