您好,我正在尝试在我的项目中使用轮胎和elasticsearch。弹性搜索和轮胎
我能够索引模型并查询它们中的每一个,但我在连接表中遇到困难。
我的模型
class Item < ActiveRecord::Base
attr_accessible :category_id, :description, :name, :rating
belongs_to :category
has_and_belongs_to_many :posts
include Tire::Model::Search
include Tire::Model::Callbacks
after_save do
update_index
end
tire.mapping do
indexes :name, :analyzer => 'snowball', :boost => 100
indexes :posts
end
end
class Post < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
has_and_belongs_to_many :tags
has_and_belongs_to_many :items
attr_accessible :posted_at, :text, :thread_id, :username
tire.mapping do
indexes :id, type: 'integer'
indexes :text, :analyzer => 'snowball', :boost => 100
indexes :thread_id, type: 'integer'
indexes :posted_at, type: 'date'
end
end
正如你可以看到我有项目和邮政
之间的连接表,如果我有一个项目的名字,我怎么可以搜索Post.search(属于那些帖子此项目)与弹性搜索或Item.search(名称).posts?
我认为轮胎不够灵活,无法做到这一点。它需要搜索两种不同的文档类型。我认为你将不得不使用轮胎查询dsl编写自己的查询。 – phoet