从我读过的所有内容来看,这应该有效。每次更改后我都会重新编制索引。
我的类别名称以复数形式存储,例如“书籍”、“电影”或“磁带”。在 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