从我读过的所有内容中都应该有效。我在每次更改后重新编制索引。
我的类别名称存储为复数,例如“书籍”,“电影”或“录音带”。在rails中,这与@resource.category.name
如果我搜索books
,则无效,但如果我搜索book
则无效。我正在努力使它能够搜索单数或复数并找到类别的结果
# Tire
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :url
indexes :title, :boost => 3
indexes :description, :boost => 2
indexes :categories do
indexes :name, analyzer: 'snowball', :boost => 1.5, store: 'true'
end
indexes :user do
indexes :username, analyzer: 'keyword'
end
end
def self.elasticsearch(params)
tire.search(
:load => { :include => [:tags] },
: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