elasticsearch - Elastic Search "Did you mean" for auto correction of words implementation not working with rails -


i trying implement full search text engine rails app using elastic search document class. should have auto correction misspelled words.

this document.rb

   require 'elasticsearch/model'     class document < applicationrecord    include elasticsearch::model    include elasticsearch::model::callbacks     belongs_to :user     document.import force: true       def self.search(query)      __elasticsearch__.search(      {       query: {         multi_match: {           query: query,           fields: ['name^10', 'service']           }         }       }     )     end     settings index: { "number_of_shards": 1,     analysis: {     analyzer: {       string_lowercase: { tokenizer: 'keyword', filter: %w(lowercase        ascii_folding) },       did_you_mean: { filter: ['lowercase'], char_filter: ['html_strip'],       type: 'custom', tokenzier: 'standard'},       autocomplete: {filter: ["lowercase", "autocompletefilter"], char_filter:        [ "html_strip"], type: "custom", tokenizer: "standard"},       default: {filter: [ "lowercase", "stopwords", "stemmer"], char_filter: [       "html_strip"], type: "custom",tokenizer: "standard"}         }        },       filter: { ascii_folding: { type: 'asciifolding', preserve_original: true        },                  stemmer: {type: 'stemmer', language: 'english'},                 autocompletefilter: { max_shingle_size: 5, min_shingle_size:2,                  type: 'shingle'},                  stopwords: {type: 'stop', stopwords: ['_english_'] }               }      }          mapping do{       document: {         properties: {           autocomplete: {             type: "string",             analyzer: "autocomplete"           },           name: {             type: "string",             copy_to: ["did_you_mean","autocomplete"]           },           did_you_mean: {             type: "string",             analyzer: "didyoumean"           },           service: {             type: "string",             copy_to: ["autocomplete", "did_you_mean"]           }         }       }     }     end    end 

it helps me search data. however, did mean phrase not working here. can further improve code?i using elastic search first time.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -