轮胎没有看到单数/复数?

时间:2012-09-28 00:55:58

标签: ruby-on-rails ruby-on-rails-3 elasticsearch tire

从我读过的所有内容中都应该有效。我在每次更改后重新编制索引。

我的类别名称存储为复数,例如“书籍”,“电影”或“录音带”。在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

0 个答案:

没有答案