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::DATE_ARRAY=> "date-array",
  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.



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

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#define_in_domain(index:) ⇒ Object



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

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)


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

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)


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

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

#returnable?Boolean

Returns:

  • (Boolean)


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

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

#searchable?Boolean

Returns:

  • (Boolean)


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

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

#sortable?Boolean

Returns:

  • (Boolean)


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

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