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

모든 결과를 얻을 :

지금 무엇을 결과하는 것은 개별 단어입니다. 예 : [ "샌프란시스코", "마드리드"라는 태그가 붙은 도시에는 세 개의 개별 태그가 생깁니다. 마찬가지로 "san francisco"(검색어 {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

예컨대 : 쿼리는 내가 대신 활성 기록을 mongoid을 사용하고 Martin martin

으로 발생합니다.

이 문제를 어떻게 해결할 수 있습니까? 나는 문제가 asciifolding tokenfilter라고 생각한다. 당신이 당신의 문제가 아직 해결

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 
+0

는 않았다 –

답변

1

내가 가진 문제를 해결? Ruby에서 테스트 단어를 연결했거나 POST 문제 일 수 있습니까?
관련 문제