Class: Workarea::Recommendation::OrderBased
- Inherits:
-
Object
- Object
- Workarea::Recommendation::OrderBased
- Defined in:
- app/queries/workarea/recommendation/order_based.rb
Instance Method Summary collapse
-
#initialize(order) ⇒ OrderBased
constructor
A new instance of OrderBased.
- #max_results ⇒ Object
- #order_category_ids ⇒ Object
- #order_product_ids ⇒ Object
- #prediction_product_ids ⇒ Object
- #related_product_ids ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(order) ⇒ OrderBased
Returns a new instance of OrderBased.
4 5 6 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 4 def initialize(order) @order = order end |
Instance Method Details
#max_results ⇒ Object
42 43 44 45 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 42 def max_results # accommodate some missing or undisplayable products Workarea.config.per_page end |
#order_category_ids ⇒ Object
38 39 40 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 38 def order_category_ids @order.items.map(&:category_ids).flatten end |
#order_product_ids ⇒ Object
34 35 36 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 34 def order_product_ids @order.items.map(&:product_id) end |
#prediction_product_ids ⇒ Object
27 28 29 30 31 32 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 27 def prediction_product_ids ProductPredictor.new.predictions_for( item_set: order_product_ids, limit: max_results ) end |
#related_product_ids ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 17 def 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 |
#results ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/queries/workarea/recommendation/order_based.rb', line 8 def results @results ||= begin result = prediction_product_ids return result if result.size == max_results (result + ).uniq.take(max_results) end end |