Class: EagleSearch::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/eagle_search/field.rb

Instance Method Summary collapse

Constructor Details

#initialize(index, column) ⇒ Field

Returns a new instance of Field.



3
4
5
6
# File 'lib/eagle_search/field.rb', line 3

def initialize(index, column)
  @index    = index
  @column   = column
end

Instance Method Details

#mappingObject



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
# File 'lib/eagle_search/field.rb', line 8

def mapping
  mapping = { type: type }
  index_settings = @index.settings

  if index_settings[:unsearchable_fields] && (index_settings[:unsearchable_fields].include?(@column.name) || index_settings[:unsearchable_fields].include?(@column.name.to_sym))
    mapping[:index] = "no"
  else
    if type == "string"
      if index_settings[:exact_match_fields] && (index_settings[:exact_match_fields].include?(@column.name) || index_settings[:exact_match_fields].include?(@column.name.to_sym))
        mapping[:index] = "not_analyzed"
      else
        mapping[:index] = "analyzed"
        mapping[:analyzer] = index_settings[:language] || "english"
        mapping[:fields] = {
          shingle: {
            type: "string",
            analyzer: "eagle_search_shingle_analyzer"
          }
        }
      end
    end
  end

  mapping
end