Class: AgnosticBackend::Cloudsearch::IndexField

Inherits:
Object
  • Object
show all
Includes:
Utilities
Defined in:
lib/agnostic_backend/cloudsearch/index_field.rb

Constant Summary collapse

TYPE_MAPPINGS =
{
  AgnosticBackend::Indexable::FieldType::STRING => "literal",
  AgnosticBackend::Indexable::FieldType::STRING_ARRAY => "literal-array",
  AgnosticBackend::Indexable::FieldType::DATE => "date",
  AgnosticBackend::Indexable::FieldType::INTEGER => "int",
  AgnosticBackend::Indexable::FieldType::DOUBLE => "double",
  AgnosticBackend::Indexable::FieldType::BOOLEAN => "literal",
  AgnosticBackend::Indexable::FieldType::TEXT => "text",
  AgnosticBackend::Indexable::FieldType::TEXT_ARRAY => "text-array",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

included

Constructor Details

#initialize(name, type) ⇒ IndexField

Returns a new instance of IndexField.



21
22
23
24
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 21

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#define_in_domain(index:) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 26

def define_in_domain(index: )
  with_exponential_backoff Aws::CloudSearch::Errors::Throttling do
    index.cloudsearch_client.define_index_field(
      :domain_name => index.domain_name,
      :index_field => definition
    )
  end
end

#equal_to_remote_field?(remote_field) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 35

def equal_to_remote_field?(remote_field)
  remote_options = remote_field.send(options_name.to_sym)
  local_options = options

  remote_field.index_field_name == name.to_s &&
    remote_field.index_field_type == cloudsearch_type &&
    local_options.all?{|k, v| v == remote_options.send(k) }
end

#facetable?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 56

def facetable?
  type.has_option(:facetable) ? !!type.get_option(:facetable) : false
end

#returnable?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 52

def returnable?
  type.has_option(:returnable) ? !!type.get_option(:returnable) : true
end

#searchable?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 48

def searchable?
  type.has_option(:searchable) ? !!type.get_option(:searchable) : true
end

#sortable?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/agnostic_backend/cloudsearch/index_field.rb', line 44

def sortable?
  type.has_option(:sortable) ? !!type.get_option(:sortable) : true
end