lib/meducation_sdk/services/recommender.rb in meducation_sdk-1.6.3 vs lib/meducation_sdk/services/recommender.rb in meducation_sdk-1.6.4

- old
+ new

@@ -8,19 +8,26 @@ attr_reader :item def initialize(item, options = {}) @item = item @options = options + @limit = options[:limit] || 5 end def recommend - generate_recommendations + recommendations = generate_recommendations + if recommendations.size < @limit + log "recommendations.size (#{recommendations.size}) is < limit of #{@limit}" + recommendations += MeducationSDK::MediaFile.where('rating > 2').per(@limit - recommendations.size).order(:random).to_a + else + log "recommendations.size (#{recommendations.size}) is >= limit of #{@limit}" + end + recommendations rescue => e log_error("!!Recommender Error!!") log_error(e.message) log_error(e.backtrace) - #Item::Recommendation.where(item_type: @item.class.name).where(item_id: @item.id).includes(:recommendation).map(&:recommendation) - [] + MeducationSDK::MediaFile.where('rating > 2').per(@limit).order(:random).to_a end def generate_recommendations groupings = {} correct_order = recommender_results.map do |result|