在Tire的语法,Elasticsearch的语法以及它们如何映射在一起时,我的头脑很艰难。
我已经通过Tire在Rails应用程序中成功编制了PDF索引。但我需要将完整的报告分解为单个页面,以便查询更精细。将PDF分成单独的页面并将其添加到belongs_to
完整报表模型的页面模型中非常容易。我正在努力的是如何设置映射以及在哪里?!?我想利用Elasticsearch的{{3}}映射,这样我才能实现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