Sha256: a725781719d2b547ad1a298b5c17d362c5ea46c9bd469946e9966f2dd607c186

Contents?: true

Size: 1.08 KB

Versions: 62

Compression:

Stored size: 1.08 KB

Contents

module Workarea
  module Recommendation
    class ProductBased
      def initialize(product)
        @product = product
        @settings = Settings.find_or_initialize_by(id: @product.id)
      end

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

      def results
        @results ||=
          begin
            results = []

            @settings.sources.each do |source|
              results.push(*send(source))
              results.uniq!

              break if results.length >= max_results
            end

            results.take(max_results)
          end
      end

      def custom
        @settings.product_ids
      end

      def purchased
        @purchased ||= Recommendation::ProductPredictor
                        .new
                        .similarities_for(@product.id, limit: max_results)
      end

      def similar
        @similar ||= Search::RelatedProducts.new(product_ids: @product.id)
                      .results
                      .map { |r| r[:catalog_id] }
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.4.13 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.12 app/queries/workarea/recommendation/product_based.rb