ruby-on-rails - Elasticsearch 和轮胎

标签 ruby-on-rails elasticsearch tire

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

相关文章:

ruby-on-rails - 通过执行回滚 Rails 迁移

sql - 如何使用 Arel 正确地向带有 'or' 和 'and' 子句的 SQL 查询添加括号?

ruby-on-rails - 正则表达式替换时区偏移量

elasticsearch - 如何在Elastic Search中从JSON字段中删除字段

elasticsearch - 在所有父项和子项字段上将Elasticsearch转换为AND

elasticsearch - 轮胎术语过滤器不起作用

ruby-on-rails - 在 GitHub 上使用 Devise Omniauth 时如何为 Rails 设置本地开发环境?

python - 安装 "elasticsearch"而不是 "pyelasticsearch"

ruby-on-rails - 将 ElasticSearch 与 Tire(A Ruby on Rails Gem)一起使用时如何限制总返回结果?

elasticsearch - 是否热衷于使用轮胎在custom_filters_score的条件过滤器上设置minimum_match?