Sha256: a1e0847b967530dc8759d2db593cd82cb6eddd17cd9f54ef740d63baa4234583

Contents?: true

Size: 991 Bytes

Versions: 1

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true
module Spree
  class User
    module Indexable
      extend ActiveSupport::Concern

      ELASTICSEARCH_SETTINGS = {
        analysis: {
          analyzer: {
            keyword_lowercase: {
              tokenizer: 'keyword',
              filter: ['lowercase']
            }
          }
        }
      }

      included do
        include Spree::Indexable

        ##
        # Define Order mapping for Elasticserach index
        #
        settings ELASTICSEARCH_SETTINGS do
          mappings dynamic: false do
            indexes :purchased_product_ids, type: 'integer'
            indexes :created_at, type: 'date'
          end
        end

        ##
        # Formats hash for elasticsearch.
        #
        def as_indexed_json(_options = {})
          as_json methods: [:purchased_product_ids]
        end

        private

        def purchased_product_ids
          orders.map(&:product_ids).flatten.uniq
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_recommendations-0.0.2 app/models/concerns/spree/user/indexable.rb