1

我使用elasticsearch_autocomplete寶石作爲自動完成功能。輪胎和elasticsearch_autocomplete口音和刻面

我遇到特殊字符ñ和口音áéíóú的問題。

型號:

class Car 
    ac_field :name, :description, :city, :skip_settings => true 

    def self.ac_search(params, options={}) 
    tire.search load: true, page: params[:page], per_page: 9 do 
     query do 
     boolean do 
      must { string params[:query], default_operator: "AND" } if params[:query].present? 
      must { term :city, params[:city] } if params[:city].present? 
     end 
     end 
     filter :term, city: params[:city] if params[:city].present? 
     facet "city" do 
     terms :city 
     end 
    end 
    end 

end 

這個版本能正常工作有特殊字符。

例如爲:與Martin查詢我得到Martín, martín, martin, Martin

所有結果通過這種方法,這就是問題所在:

現在是什麼結果是單個單詞。例如一個標記爲「舊金山」,「馬德里」的城市最終會有三個單獨的標籤。同樣,如果我在「舊金山」(必須{term'city',params [:city]})「上進行查詢,將會失敗,而對」San「或」Francisco「的查詢將會成功。這裏所期望的行爲是標籤應該是原子的,所以只有「舊金山」(或「馬德里」)標籤搜索才能成功。

要解決這個問題,我創建我的自定義映射關係:相反

得到的:

model = self 
    settings ElasticsearchAutocomplete::Analyzers::AC_BASE do 
    mapping _source: {enabled: true, includes: %w(name description city)} do 
     indexes :name, model.ac_index_config(:name) 
     indexes :description, model.ac_index_config(:description) 
     indexes :city, :type => 'string', :index => :not_analyzed 
    end 
    end 

有了這個映射多字的問題是固定的,現在用city場面正常工作類型的刻面SanFrancisco現在我得到San Francisco

現在,問題是,在模型內部的映射下,搜索不會找到具有特殊字符的結果ERS

Martin

例如爲:查詢我只得到結果與Martin martin

我使用mongoid而不是活動記錄。

我該如何解決這個問題?我認爲問題出在asciifolding tokenfilter

+0

你解決你的問題了嗎?你在Ruby中插入測試單詞還是可能是POST問題? –

回答

1

我固定的問題:

class User 
    include Mongoid::Document 
    field :city, :type => String 
    has_one: car 
end 

class Car 
    ac_field :name, :description, :user_city, :skip_settings => true 
    def self.ac_search(params, options={}) 
    tire.search load: true, page: params[:page], per_page: 9 do 
     query do 
     boolean do 
      must { term :user_city, params[:user_city] } if params[:user_city].present? 
     end 
     end 
     facet "cities" do 
     terms :user_city 
     end 
    end 
    end 

    model = self 
    settings ElasticsearchAutocomplete::Analyzers::AC_BASE do 
    mapping _source: {enabled: true, includes: %w(car_city name description)} do 
    indexes :car_city, :type => 'string', :index => :not_analyzed 
    end 
    end 

    def to_indexed_json 
    to_json(methods: [:user_city]) 
    end 
    def user_city 
    user.city 
    end 
end