Browse files

Merge pull request #48 from ericmhalvorsen/master

Allow offset as an option for matcher.
  • Loading branch information...
2 parents 1e4fd17 + a0e4992 commit ead5d6c2b6d698a5c49294a73a4f7536a5013f01 @josegonzalez josegonzalez committed Aug 17, 2015
Showing with 2 additions and 2 deletions.
  1. +2 −2 lib/soulmate/matcher.rb
View
4 lib/soulmate/matcher.rb
@@ -3,7 +3,7 @@ module Soulmate
class Matcher < Base
def matches_for_term(term, options = {})
- options = { :limit => 5, :cache => true }.merge(options)
+ options = { :limit => 5, :cache => true, :offset => 0 }.merge(options)
words = normalize(term).split(' ').reject do |w|
w.size < Soulmate.min_complete or Soulmate.stop_words.include?(w)
@@ -19,7 +19,7 @@ def matches_for_term(term, options = {})
Soulmate.redis.expire(cachekey, 10 * 60) # expire after 10 minutes
end
- ids = Soulmate.redis.zrevrange(cachekey, 0, options[:limit] - 1)
+ ids = Soulmate.redis.zrevrange(cachekey, options[:offset], options[:limit] - 1)
if ids.size > 0
results = Soulmate.redis.hmget(database, *ids)
results = results.reject{ |r| r.nil? } # handle cached results for ids which have since been deleted

0 comments on commit ead5d6c

Please sign in to comment.