繁体   English   中英

Rails,Tire,Elasticsearch:如何使用同义词?

[英]Rails, Tire, Elasticsearch: how to use synonyms?

我不知道如何通过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

我在文档中找不到任何内容

谢谢!

我想你的意思是弹性搜索的同义词 - 标记过滤器: 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" }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM