Sha256: 09a2639fdf3b523bc8b0ebb4746dd9a688c93b37e5c7276b82dc46c3688a1e64

Contents?: true

Size: 1.14 KB

Versions: 28

Compression:

Stored size: 1.14 KB

Contents

module Workarea
  module Recommendation
    class UserActivityBased
      def initialize(metrics)
        @metrics = metrics
      end

      def results
        if recent_product_ids.blank? && recent_category_ids.blank?
          popular_product_ids.take(max_results)
        else
          related_product_ids.take(max_results)
        end
      end

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

      def recent_product_ids
        @metrics.viewed.recent_product_ids(unique: true)
      end

      def recent_category_ids
        @metrics.viewed.recent_category_ids(unique: true)
      end

      def popular_product_ids
        Insights::TopProducts
          .current
          .results
          .map { |r| r['product_id'] }
          .take(max_results)
      end

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

        query.results.map { |r| r[:catalog_id] }
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.26 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.25 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.23 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.22 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.21 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.20 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.19 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.18 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.17 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.16 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.15 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.14 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.13 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.12 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.11 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.10 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.9 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.8 app/queries/workarea/recommendation/user_activity_based.rb
workarea-core-3.5.7 app/queries/workarea/recommendation/user_activity_based.rb