Class: Chewy::Index::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/chewy/index/settings.rb

Overview

Stores ElasticSearch index settings and resolves analysis hash. At first, you need to store some analyzers or other analysis options to the corresponding repository:

title_nysiis filter here will be expanded automatically when title_analyzer analyser will be used in index settings:

Additional analysing options, which wasn't stored in repositories, might be used as well.

Examples:

Chewy.analyzer :title_analyzer, type: 'custom', filter: %w(lowercase icu_folding title_nysiis)
Chewy.filter :title_nysiis, type: 'phonetic', encoder: 'nysiis', replace: false
class ProductsIndex < Chewy::Index
  settings analysis: {
    analyzer: [
      'title_analyzer',
      {one_more_analyzer: {type: 'custom', tokenizer: 'lowercase'}}
    ]
  }
end

Instance Method Summary collapse

Constructor Details

#initialize(params = {}, &block) ⇒ Settings

Returns a new instance of Settings.



28
29
30
31
# File 'lib/chewy/index/settings.rb', line 28

def initialize(params = {}, &block)
  @params = params
  @proc_params = block
end

Instance Method Details

#to_hashObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/chewy/index/settings.rb', line 33

def to_hash
  settings = @params.deep_symbolize_keys
  settings.merge!((@proc_params.call || {}).deep_symbolize_keys) if @proc_params

  settings[:analysis] = resolve_analysis(settings[:analysis]) if settings[:analysis]

  if settings[:index] || Chewy.configuration[:index]
    settings[:index] = (Chewy.configuration[:index] || {})
      .deep_merge((settings[:index] || {}).deep_symbolize_keys)
  end

  settings.present? ? {settings: settings} : {}
end