Class: Workarea::Recommendation::ProductBased
- Inherits:
-
Object
- Object
- Workarea::Recommendation::ProductBased
- Defined in:
- app/queries/workarea/recommendation/product_based.rb
Instance Method Summary collapse
- #custom ⇒ Object
-
#initialize(product) ⇒ ProductBased
constructor
A new instance of ProductBased.
- #max_results ⇒ Object
- #purchased ⇒ Object
- #results ⇒ Object
- #similar ⇒ Object
Constructor Details
#initialize(product) ⇒ ProductBased
Returns a new instance of ProductBased.
4 5 6 7 |
# File 'app/queries/workarea/recommendation/product_based.rb', line 4 def initialize(product) @product = product @settings = Settings.find_or_initialize_by(id: @product.id) end |
Instance Method Details
#custom ⇒ Object
30 31 32 |
# File 'app/queries/workarea/recommendation/product_based.rb', line 30 def custom @settings.product_ids end |
#max_results ⇒ Object
9 10 11 12 |
# File 'app/queries/workarea/recommendation/product_based.rb', line 9 def max_results # accommodate some missing or undisplayable products Workarea.config.per_page end |
#purchased ⇒ Object
34 35 36 37 38 |
# File 'app/queries/workarea/recommendation/product_based.rb', line 34 def purchased @purchased ||= Recommendation::ProductPredictor .new .similarities_for(@product.id, limit: max_results) end |
#results ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/queries/workarea/recommendation/product_based.rb', line 14 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 |
#similar ⇒ Object
40 41 42 43 44 |
# File 'app/queries/workarea/recommendation/product_based.rb', line 40 def similar @similar ||= Search::RelatedProducts.new(product_ids: @product.id) .results .map { |r| r[:catalog_id] } end |