Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #48 from ericmhalvorsen/master
Browse files Browse the repository at this point in the history
Allow offset as an option for matcher.
  • Loading branch information
josegonzalez committed Aug 17, 2015
2 parents 1e4fd17 + a0e4992 commit ead5d6c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/soulmate/matcher.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ead5d6c

Please sign in to comment.