Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle recommendations for non-existing items gracefully #4

Closed
wants to merge 1 commit into from

2 participants

@egze

Previously when you try to get recommendations for non-existing items - you would get an exception "undefined method `split' for nil:NilClass".

Now you just get an empty array.

@paulasmuth
Owner

With specs -> awesome. Thanks! :)

@paulasmuth paulasmuth closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 0 deletions.
  1. +1 −0  lib/recommendify/similarity_matrix.rb
  2. +5 −0 spec/base_spec.rb
View
1  lib/recommendify/similarity_matrix.rb
@@ -44,6 +44,7 @@ def commit_item!(item_id)
# use activesupport's orderedhash?
def retrieve_item(item_id)
data = Recommendify.redis.hget(redis_key, item_id)
+ return {} if data.nil?
Hash[data.split("|").map{ |i| (k,s=i.split(":")) && [k,s.to_f] }]
end
View
5 spec/base_spec.rb
@@ -133,6 +133,11 @@
sm.similarity_matrix.should_receive(:[]).with("fnorditem").and_return({:fooitem => 0.4, :baritem => 1.5})
sm.for("fnorditem").length.should == 2
end
+
+ it "should not throw exception for non existing items" do
+ sm = Recommendify::Base.new
+ sm.for("not_existing_item").length.should == 0
+ end
it "should retrieve the n-most similar neighbors as Recommendify::Neighbor objects" do
sm = Recommendify::Base.new
Something went wrong with that request. Please try again.