Class: AgnosticBackend::Elasticsearch::IndexField

Inherits:
Object
  • Object
show all
Defined in:
lib/agnostic_backend/elasticsearch/index_field.rb

Constant Summary collapse

TYPE_MAPPINGS =
{
  AgnosticBackend::Indexable::FieldType::STRING => "string",
  AgnosticBackend::Indexable::FieldType::STRING_ARRAY => "string",
  AgnosticBackend::Indexable::FieldType::DATE => "date",
  AgnosticBackend::Indexable::FieldType::DATE_ARRAY => "date",
  AgnosticBackend::Indexable::FieldType::INTEGER => "integer",
  AgnosticBackend::Indexable::FieldType::DOUBLE => "double",
  AgnosticBackend::Indexable::FieldType::BOOLEAN => "boolean",
  AgnosticBackend::Indexable::FieldType::TEXT => "string",
  AgnosticBackend::Indexable::FieldType::TEXT_ARRAY => "string",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ IndexField

Returns a new instance of IndexField.



19
20
21
22
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 19

def initialize(name, type)
  @name = name
  @type = type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 17

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



17
18
19
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 17

def type
  @type
end

Instance Method Details

#analyzed?Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 24

def analyzed?
  (type.type == AgnosticBackend::Indexable::FieldType::TEXT) ||
  (type.type == AgnosticBackend::Indexable::FieldType::TEXT_ARRAY)
end

#analyzed_propertyObject



41
42
43
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 41

def analyzed_property
  analyzed? ? {} : { "index" => "not_analyzed" }
end

#definitionObject



33
34
35
36
37
38
39
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 33

def definition
  {
    name.to_s => {
      "type" => elasticsearch_type
    }.merge(analyzed_property)
  }
end

#elasticsearch_typeObject



29
30
31
# File 'lib/agnostic_backend/elasticsearch/index_field.rb', line 29

def elasticsearch_type
  @elasticsearch_type ||= TYPE_MAPPINGS[type.type]
end