Permalink
Browse files

Code for filtering results

  • Loading branch information...
rixth committed May 10, 2011
1 parent f9a60ea commit c745943b5d760544a341d14daac6e75f178fa6c4
Showing with 9 additions and 2 deletions.
  1. +1 −1 lib/soulmate/loader.rb
  2. +8 −1 lib/soulmate/matcher.rb
View
@@ -37,7 +37,7 @@ def load(items)
filters.each_pair do |index, value|
value = normalize(value).gsub(/ /, '')
- Soulmate.redis.sadd("#{base}:#{p}:filters:#{index}:#{value}", id)
+ Soulmate.redis.zadd("#{base}:#{p}filters:#{index}:#{value}", 0, id)
end
items_loaded += 1
end
View
@@ -8,11 +8,18 @@ def matches_for_term(term, options = {})
end.sort
options[:limit] ||= 5
+ options[:filters] ||= {}
- cachekey = "#{cachebase}:" + words.join('|')
+ cachekey = "#{cachebase}:" + words.join('|') + ":" + options[:filters].to_s
if !Soulmate.redis.exists(cachekey)
interkeys = words.map { |w| "#{base}:#{w}" }
+
+ interkeys += options[:filters].to_a.map do |filter|
+ value = filter.last.downcase.strip.gsub(/ /, '')
+ "#{base}:filters:#{filter.first}:#{value}"
+ end
+ p interkeys
Soulmate.redis.zinterstore(cachekey, interkeys)
Soulmate.redis.expire(cachekey, 10 * 60) # expire after 10 minutes
end

0 comments on commit c745943

Please sign in to comment.