Sha256: 350f4f215cac50ba0450858efb7d472e4c93ba8151c648d3dbc143c7ea3692b2

Contents?: true

Size: 1.13 KB

Versions: 62

Compression:

Stored size: 1.13 KB

Contents

module Workarea
  module Recommendation
    class OrderBased
      def initialize(order)
        @order = order
      end

      def results
        @results ||=
          begin
            result = prediction_product_ids
            return result if result.size == max_results
            (result + related_product_ids).uniq.take(max_results)
          end
      end

      def related_product_ids
        query = Workarea::Search::RelatedProducts.new(
          product_ids: order_product_ids,
          category_ids: order_category_ids,
          exclude_product_ids: order_product_ids
        )

        query.results.map { |r| r[:catalog_id] }.first(max_results)
      end

      def prediction_product_ids
        ProductPredictor.new.predictions_for(
          item_set: order_product_ids,
          limit: max_results
        )
      end

      def order_product_ids
        @order.items.map(&:product_id)
      end

      def order_category_ids
        @order.items.map(&:category_ids).flatten
      end

      def max_results
        # accommodate some missing or undisplayable products
        Workarea.config.per_page
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.26 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.45 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.25 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.23 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.44 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.22 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.43 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.21 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.42 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.20 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.41 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.19 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.40 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.18 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.39 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.17 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.38 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.5.16 app/queries/workarea/recommendation/order_based.rb
workarea-core-3.4.37 app/queries/workarea/recommendation/order_based.rb