每个ActiveModel / Record有多个映射?

时间:2012-11-30 08:14:31

标签: autocomplete elasticsearch tire n-gram

假设我想在像BlogPosts之类的东西上创建两个单独的索引,这样我就可以使用一个索引进行快速搜索(例如用于自动完成目的),然后使用另一个索引进行完整的搜索查询。

这是我可以用轮胎做的事吗? 所以这样的事情(原谅我,如果它有点原始)

class Post < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks

   index_name 'autocomplete'
  mapping do
      indexes :title, :analyzer => 'my_ngram_analyzer'
  end

  index_name 'main'
  mapping do 
      indexes :title
      indexes :description
      indexes :author
      indexes :published_on
  end
end

回调知道在适当的索引中添加和删除新帖子

1 个答案:

答案 0 :(得分:1)

你不能在Tire中这样做,使用mapping DSL方法在一个类中设置两个单独的索引(和映射)。

使用两个单独的索引可能是个好主意,一个用于自动完成,另一个用于搜索。有一个不错的tutorial,StackOverflow answer,甚至还有一个弹性搜索plugin可以帮助您入门。

但是,除非您拥有大量数据,否则即使使用单个索引,也可以使用multi_field类型,跨多个字段的match查询以及可能的NGram来实现这一目标基于分析仪。

查看概述该方法的Autocomplete with Tire教程。


来自https://github.com/karmi/tire/issues/531

的交叉发布