2017-01-09 3 views
0

나는 내 레일 앱에서 단어를 검색하기 위해 elasticsearch-rails와 elasticsearch-model gem을 사용하고 있습니다. 여기 Elasticsearch-rails 결과가 정확하지 않음

내가 단어를 어떻게 검색하나요되는 장소를

require 'elasticsearch/model' 

    class Article < ActiveRecord::Base 
     include Elasticsearch::Model 
     include Elasticsearch::Model::Callbacks 

     settings index: { number_of_shards: 1 } do 
     mappings dynamic: 'false' do 
      indexes :title, analyzer: 'english', index_options: 'offsets' 
      indexes :text, analyzer: 'english' 
     end 
     end 

     def self.search(query) 
     __elasticsearch__.search(
      { 
      query: { 
       multi_match: { 
       query: query, 
       fields: ['title^10', 'text'] 
       } 
      }, 
      highlight: { 
       pre_tags: ['<em>'], 
       post_tags: ['</em>'], 
       fields: { 
       title: {}, 
       text: {} 
       } 
      } 
      } 
     ) 
     end 
    end 

    # Delete the previous articles index in Elasticsearch 
    Article.__elasticsearch__.client.indices.delete index: Article.index_name rescue nil 

    # Create the new index with the new mapping 
    Article.__elasticsearch__.client.indices.create \ 
     index: Article.index_name, 
     body: { settings: Article.settings.to_hash, mappings: Article.mappings.to_hash } 

    # Index all article records from the DB to Elasticsearch 
    Article.import 

    #Article.import force: true 

내 질문을하는 검색 할 내 모델? 티셔츠, 티셔츠, 티셔츠 모두 일치해야합니다. 추가 연구를위한 링크도 도움이됩니다. 고마워요

답변

0

찾고 계시는 키워드는 모호합니다. 또는 (2는 fuzziest 검색 가능한 의미 임) 그 0과 2 사이의 정수를 받아, http://dev.mikamai.com/post/85901585484/elasticsearch-on-rails-a-primer

records = Article.search(query: {match: {_all: {query: 'wold', fuzziness: 2}}}).records 
records.first.title # => "Hello World" 

는 번짐이 최대 허용 Levenshtein 거리를 나타냄

예 블로그 게시물보기 검색어의 검색어 길이에 따라 편집 거리를 생성하는 "AUTO"문자열입니다.

관련 문제