Sha256: 3b0889213cb702675fca44e385662fc630742501931a944a701bb156f5ee2c3f

Contents?: true

Size: 779 Bytes

Versions: 2

Compression:

Stored size: 779 Bytes

Contents

module Recommendations
  class Item
    module Similarity
      def similars(count = Recommendations.configuration.similar_users_count)
        Recommendations.redis.zrange("recommendations:similars:item:#{id}", 0, count - 1)
      end

      def update_similars
        Recommendations.redis.del("recommendations:similars:item:#{id}")

        categories.each do |category, score|
          items = Recommendations.redis.hgetall("recommendations:categories:#{category}")

          items.reject {|k, v| k == id}.each do |item, item_score|
            difference = (Float(item_score) - Float(score)).abs
            Recommendations.redis.zincrby("recommendations:similars:item:#{id}", difference, item)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
recommendations2-0.0.5 lib/recommendations/item/similarity.rb
recommendations2-0.0.4 lib/recommendations/item/similarity.rb