【发布时间】:2012-09-26 23:23:24
【问题描述】:
我有几个关于 Rails + Tire + ElasticSearch 的非常具体的问题。
我看过 Railscast 关于它的内容,也阅读了很多文档,但老实说,这超出了我的想象。我希望有人能帮助我理解我无法完全掌握的细节。
这是我模型中的 Resource.rb 弹性搜索部分:
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :url
indexes :title, :boost => 3
indexes :description, :boost => 2
indexes :category, :boost => 1.5, type: 'object',
properties: {
name: { type: 'multi_field',
fields: { name: { type: 'string', analyzer: 'keyword' } } } }
indexes :user, type: 'object',
properties: {
username: { type: 'multi_field',
fields: { username: { type: 'string', analyzer: 'keyword' } } } }
end
def self.elasticsearch(params)
tire.search(load: true, page: params[:page], per_page: 20) do
query { string params[:e], default_operator: "OR" } if params[:e].present?
end
end
def to_indexed_json
to_json( include: { user: { only: [:username] },
category: { only: [:name] }
} )
end
- “未分析”是什么意思?在我正在阅读的许多教程中,他们都使用它。如果不分析,为什么会包含在
mapping do中? - 使用索引的目的是什么。例如,
indexes :id, type: 'integer'之类的东西。为什么需要对整数进行索引,这对性能有帮助吗? - 如何修改 URL 的分析器以使其更好地工作?例如,如果它存储为
http://www.dropbox.com,则搜索dropbox.com不会找到结果,但www.dropbox.com会。我尝试粘贴所有不同的分析器,但它们都不适用于 URL - 如果我的
category.name存储为复数形式,例如“books”、“movies”、“tapes”,我如何告诉分析器根据单数和复数来查看这个词。搜索“电影”无效,但“电影”有效 - 当我删除
load: true时,我的整个网站都会中断。他在railscast中回顾了这一点,但只是片刻。这是否意味着我需要将每个属性(和关联)移动到映射中,并将其更改为 :not_analyzed? (我刚刚意识到......也许我只是回答了我自己的问题 #1!)。 - 一般来说,哪种类型的数据最适合 OR,哪种数据最适合 AND?就获得更多结果而言,我正在考虑或似乎更宽容
【问题讨论】:
标签: ruby-on-rails ruby lucene elasticsearch tire