gpt4 book ai didi

ruby-on-rails - Elasticsearch 和轮胎

转载 作者:行者123 更新时间:2023-12-03 02:09:00 25 4
gpt4 key购买 nike

您好,我正在尝试在我的项目中使用tire和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

如您所见,我在Item和Post之间有一个联接表

如果我有商品名称,该如何通过 Elasticsearch 或Item.search(name).posts来搜索Post.search(属于该商品的帖子)?

最佳答案

可能最好的办法就是从这里开始:

http://stackoverflow.com/questions/11692560/elasticsearch-tire-and-nested-queries-associations-with-activerecord/11711477#11711477

然后看 http://railscasts.com/episodes/307-elasticsearch-part-2
然后从上到下浏览轮胎 http://karmi.github.io/retire/
我正在解决类似问题...会让您知道我如何解决问题:)

关于ruby-on-rails - Elasticsearch 和轮胎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19204878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com