module Cauchy::IndexSchema::Normalization
Constants
- IGNORE_SETTINGS
Public Instance Methods
normalize_field(key, field)
click to toggle source
# File lib/cauchy/index_schema/normalization.rb, line 23 def normalize_field(key, field) if field.key?('properties') field['properties'] = normalize_mapping(field['properties']) field['type'] ||= 'object' end if field['type'] == 'date' field['format'] ||= 'dateOptionalTime' end if ['boolean', 'long', 'double', 'date'].include?(field['type']) field.delete('analyzer') field['index'] ||= 'not_analyzed' end if key == 'properties' field = normalize_mapping(field) else field = normalize_value(field) end return [key, field] end
normalize_mapping(hash)
click to toggle source
# File lib/cauchy/index_schema/normalization.rb, line 13 def normalize_mapping(hash) hash.deep_stringify_keys.sort.map do |key, field| if field.is_a?(Hash) normalize_field(key, field) else [key, field] end end.to_h end
normalize_settings(hash)
click to toggle source
# File lib/cauchy/index_schema/normalization.rb, line 47 def normalize_settings(hash) normalize_value(hash.deep_stringify_keys.except(*IGNORE_SETTINGS)) end
normalize_value(value)
click to toggle source
# File lib/cauchy/index_schema/normalization.rb, line 51 def normalize_value(value) case value when Hash value.sort.map {|key, v| [key, normalize_value(v)] }.to_h when Numeric value.to_s else value end end