我很难理解 Tire 的语法、Elasticsearch 的语法以及它们是如何映射在一起的。
我已经通过轮胎成功地在 Rails 应用程序中索引了 PDF。但是我需要将完整的报告分解为单独的页面,以便查询可以更加细化。将 PDF 拆分为单独的页面并将它们添加到belongs_to
完整报告模型的页面模型很容易。我正在努力的是如何设置映射以及在哪里?!?我想利用 Elasticsearch 的Parent Field映射来实现这个最终目标。
希望有人可以让我直截了当。
报告模型(如果我将整个 PDF 索引为 ,这对我有用:attachment
):
class Report < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
has_many :pages, :dependent => :destroy
attr_accessible :filename, :title
tire.mapping do
indexes :id, :type =>'integer'
indexes :title
indexes :attachment, :type => 'attachment',
:fields => {
:content_type => { :store => 'yes' },
:author => { :store => 'yes' },
:title => { :store => 'yes' },
:attachment => { :term_vector => 'with_positions_offsets', :store => 'yes' },
:date => { :store => 'yes' }
}
end
...
end
页面模型:
class Page < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
belongs_to :report
attr_accessible :filename, :page_num,
tire.mapping do
indexes :id, :type => 'integer'
indexes :page_num, :type => 'integer'
indexes :report_id, :type => 'integer' ###<== how is this associated with _parent?
indexes :attachment, :type => 'attachment',
:fields => {
...
...
end
end