Sha256: 33eabf0aae5c9e941fd7f63aa69b25ecdf30cc1f89c1024aacf46827ee7a4c83

Contents?: true

Size: 969 Bytes

Versions: 1

Compression:

Stored size: 969 Bytes

Contents

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.1 app/models/concerns/spree/user/indexable.rb