Sha256: ead10a7d8aac1404ee711616eead60924e988fde84e0f5d1d9d4a43f92e1f25d

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

module AgnosticBackend
  module Elasticsearch
    class IndexField

      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

      attr_reader :name, :type

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

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

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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
agnostic_backend-1.0.4 lib/agnostic_backend/elasticsearch/index_field.rb
agnostic_backend-1.0.3 lib/agnostic_backend/elasticsearch/index_field.rb
agnostic_backend-1.0.2 lib/agnostic_backend/elasticsearch/index_field.rb
agnostic_backend-1.0.1 lib/agnostic_backend/elasticsearch/index_field.rb
agnostic_backend-1.0.0 lib/agnostic_backend/elasticsearch/index_field.rb
agnostic_backend-0.9.9 lib/agnostic_backend/elasticsearch/index_field.rb