class AgnosticBackend::Cloudsearch::IndexField

Constants

TYPE_MAPPINGS

Attributes

name[R]
type[R]

Public Class Methods

new(name, type) click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 22
def initialize(name, type)
  @name = name
  @type = type
end

Public Instance Methods

define_in_domain(index: ) click to toggle source
# 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) click to toggle source
# 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?() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 57
def facetable?
  type.has_option(:facetable) ? !!type.get_option(:facetable) : false
end
returnable?() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 53
def returnable?
  type.has_option(:returnable) ? !!type.get_option(:returnable) : true
end
searchable?() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 49
def searchable?
  type.has_option(:searchable) ? !!type.get_option(:searchable) : true
end
sortable?() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 45
def sortable?
  type.has_option(:sortable) ? !!type.get_option(:sortable) : true
end

Private Instance Methods

cloudsearch_type() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 63
def cloudsearch_type
  @cloudsearch_type ||= TYPE_MAPPINGS[type.type]
end
definition() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 67
def definition
  {
    :index_field_name => name.to_s,
    :index_field_type => cloudsearch_type,
    options_name.to_sym => options
  }
end
options() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 79
def options
  opts = {
      :sort_enabled => sortable?,
      :search_enabled => searchable?,
      :return_enabled => returnable?,
      :facet_enabled => facetable?
    }
  # certain parameters are not included acc. to cloudsearch type
  # we filter them out here
  case cloudsearch_type
  when 'text-array'
    opts.delete(:sort_enabled)
    opts.delete(:search_enabled)
    opts.delete(:facet_enabled)
  when 'text'
    opts.delete(:search_enabled)
    opts.delete(:facet_enabled)
  when 'literal-array'
    opts.delete(:sort_enabled)
  when 'date-array'
    opts.delete(:sort_enabled)
  end
  opts
end
options_name() click to toggle source
# File lib/agnostic_backend/cloudsearch/index_field.rb, line 75
def options_name
  "#{cloudsearch_type.gsub('-', '_')}_options"
end