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.5.27 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.26 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.45 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.25 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.23 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.44 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.22 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.43 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.21 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.42 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.20 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.41 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.19 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.40 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.18 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.39 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.17 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.38 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.5.16 app/queries/workarea/recommendation/product_based.rb
workarea-core-3.4.37 app/queries/workarea/recommendation/product_based.rb