Module: Elasticsearch::Autocomplete::Filters::ClassMethods

Included in:
Elasticsearch::Autocomplete::Filters
Defined in:
lib/elasticsearch/autocomplete/filters.rb

Instance Method Summary collapse

Instance Method Details

#analysisObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/elasticsearch/autocomplete/filters.rb', line 8

def analysis
  {
    analysis: {
      analyzer: {
        simple: {
          type: "custom",
          tokenizer: "keyword",
          filter: [ "asciifolding", "keyword", "lowercase" ]
        },
        autocomplete: {
          type: "custom",
          tokenizer: "standard",
          filter: [ 'asciifolding', "standard", "lowercase", "kstem", "ngram_beginning" ]
        },
        fuzzy: {
          type: "custom",
          tokenizer: "standard",
          filter: [ 'asciifolding', "standard", "lowercase", "kstem", "ngram_short" ]
        },
        beginning: {
          type: "custom",
          tokenizer: "keyword",
          filter: [ "lowercase", 'asciifolding', 'ngram_beginning' ]
        }
      },
      filter: {
        ngram_beginning: {
          type: "edgeNGram",
          min_gram: 1,
          max_gram: 45
        },
        ngram_short: {
          type: "ngram",
          min_gram: 1,
          max_gram: 15
        }
      }
    }
  }
end

#build_config(field, add_options_to_fields = {}) ⇒ Object Also known as: config



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/elasticsearch/autocomplete/filters.rb', line 49

def build_config(field, add_options_to_fields={})
  {
    :type => :multi_field,
    :fields => {
      field.to_sym => { type: 'string' }.merge(add_options_to_fields),
      :"#{field}.exact" => { type: 'string', index_analyzer: 'simple' }.merge(add_options_to_fields),
      :"#{field}.beginning" => { type: 'string', index_analyzer: 'beginning'}.merge(add_options_to_fields),
      :"#{field}.autocomplete" => { type: 'string', index_analyzer: 'autocomplete'}.merge(add_options_to_fields),
      :"#{field}.fuzzy" => { type: 'string', index_analyzer: 'fuzzy'}.merge(add_options_to_fields)
    }
  }
end