您好,我正在嘗試在我的項目中使用輪胎和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