我正在使用 ElasticSearch 和 Tire 来索引和搜索 mongoid 模型,并且我一直在寻找索引和搜索嵌入式关联的“正确”方法。我为此模型设置了一个功能齐全的设置,但由于某种原因,我可以搜索除嵌入式模型(ResourceTag)中的字段之外的所有内容
删除了不必要的代码
class Resource
include Mongoid::Document
include Tire::Model::Search
include Tire::Model::Callbacks
include Mongoid::Timestamps
embeds_many :tags, :class_name => "ResourceTag"
accepts_nested_attributes_for :tags, :allow_destroy => true
# Tire
mapping do
indexes :_id
indexes :version, analyzer: 'snowball', boost: 100
indexes :created_at, type: 'date', index: :not_analyzed
indexes :updated_at, type: 'date', index: :not_analyzed
indexes :assignment do
indexes :_id
indexes :name, analyzer: 'snowball', boost: 100
indexes :current_state, analyzer: 'snowball', boost: 100
do
indexes :resource_files do
indexes :_id
indexes :name, analyzer: 'snowball', boost: 100
end
indexes :tags do
indexes :_id
indexes :name, analyzer: 'snowball', boost: 100
end
end
def to_indexed_json
self.to_json(
:include => {
:assignment => {
:methods => :formatted_current_state
},
:resource_files => {
:methods => [:is_video, :is_image]
},
:tags => nil
}
)
end
end
class ResourceTag
include Mongoid::Document
# Attributes
attr_accessible :name
# Fields
field :name, :type => String
# Validations
validates_presence_of :name
validates_uniqueness_of :name, :case_sensitive => false
# Relations
embedded_in :resource
end
我不太确定我的代码有什么问题,但我确定我以前可以正常工作,现在它搞砸了:s
我正在寻找一个带有 mongoid 和嵌入式文档的轮胎示例,但没有运气,而且我已经没有想法了。
感谢您的任何想法和贡献。