0

我不知道如何通过 Tire gem 使用 Elasticsearch 的同义词/复数。我有一个要下载的同义词文件(一个英文就够了)吗?无论我是否使用轮胎,都需要在 ES 中进行设置吗?

class Story < ActiveRecord::Base
  include Tire::Model::Search
  include Tire::Model::Callbacks
  attr_accessible :author, :content, :title

  mapping do
    indexes :id, :index => :not_analyzed
    indexes :author, :analyzer => 'keyword'
    indexes :title, :analyzer => 'snowball'
    indexes :content, :analyzer => 'snowball'
  end
end

class StoriesController < ApplicationController
  def index
    if params[:q].present?
      p = params
      @stories = Story.search(per_page: 30, page: params[:page], load: true) do
        query { string p[:q], default_operator: 'AND' }
      end
    end
  end
end

我在文档中什么也没找到...

谢谢!

4

1 回答 1

2

我猜你的意思是弹性搜索的同义词-tokenfilter:http ://www.elasticsearch.org/guide/reference/index-modules/analysis/synonym-tokenfilter/

{
    "index" : {
        "analysis" : {
            "analyzer" : {
                "synonym" : {
                    "tokenizer" : "whitespace",
                    "filter" : ["synonym"]
                }
            },
            "filter" : {
                "synonym" : {
                    "type" : "synonym",
                    "synonyms_path" : "analysis/synonym.txt"
                }
            }
        }
    }
}

轮胎中的afaik,这将进入settings配置:

  settings :analysis => {
             :filter => {
               :synonym  => {
                 "type"          => "synonym",
                 "synonyms_path" => Rails.root.join("config/analysis/synonym.txt").to_s
               }
             },
             :analyzer => {
               :synonym => {
                  "tokenizer"    => "lowercase",
                  "filter"       => ["synonym"],
                  "type"         => "custom" }
             }
           } do
    mapping { indexes :the_field, :type => 'string', :analyzer => "synonym" }
于 2013-06-30T16:27:02.143 回答