lunar 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/lunar.rb +5 -3
- data/lib/lunar/keyword_matches.rb +3 -1
- data/lib/lunar/result_set.rb +4 -0
- data/lunar.gemspec +1 -1
- data/test/test_lunar.rb +14 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.2
|
data/lib/lunar.rb
CHANGED
@@ -4,7 +4,7 @@ require 'nest'
|
|
4
4
|
require 'text'
|
5
5
|
|
6
6
|
module Lunar
|
7
|
-
VERSION = '0.5.
|
7
|
+
VERSION = '0.5.2'
|
8
8
|
|
9
9
|
autoload :Connection, "lunar/connection"
|
10
10
|
autoload :LunarNest, "lunar/lunar_nest"
|
@@ -83,7 +83,7 @@ module Lunar
|
|
83
83
|
# @return Lunar::ResultSet an Enumerable object.
|
84
84
|
def self.search(namespace, options, finder = lambda { |id| namespace[id] })
|
85
85
|
sets = find_and_combine_sorted_sets_for(namespace, options)
|
86
|
-
key = try_intersection_of_sorted_sets(namespace, sets)
|
86
|
+
key = try_intersection_of_sorted_sets(namespace, sets, options)
|
87
87
|
|
88
88
|
ResultSet.new(key, nest[namespace], finder)
|
89
89
|
end
|
@@ -121,7 +121,9 @@ private
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
def self.try_intersection_of_sorted_sets(namespace, sets)
|
124
|
+
def self.try_intersection_of_sorted_sets(namespace, sets, options)
|
125
|
+
return if sets.empty?
|
126
|
+
|
125
127
|
if sets.size == 1
|
126
128
|
sets.first
|
127
129
|
else
|
@@ -11,6 +11,8 @@ module Lunar
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def distkey
|
14
|
+
return if keys.flatten.empty?
|
15
|
+
|
14
16
|
nest[{ att => value }.hash].tap do |dk|
|
15
17
|
dk.zunionstore keys.flatten
|
16
18
|
end
|
@@ -29,4 +31,4 @@ module Lunar
|
|
29
31
|
Words.new(value).map { |word| Lunar.metaphone(word) }
|
30
32
|
end
|
31
33
|
end
|
32
|
-
end
|
34
|
+
end
|
data/lib/lunar/result_set.rb
CHANGED
@@ -33,6 +33,8 @@ module Lunar
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def each
|
36
|
+
return if not distkey
|
37
|
+
|
36
38
|
objects(distkey.zrange(0, -1)).each { |e| yield e }
|
37
39
|
end
|
38
40
|
|
@@ -86,6 +88,8 @@ module Lunar
|
|
86
88
|
# @return [Array] Array of objects as defined by the `finder`.
|
87
89
|
# @see http://code.google.com/p/redis/wiki/SortCommand
|
88
90
|
def sort(opts = {})
|
91
|
+
return [] if not distkey
|
92
|
+
|
89
93
|
opts[:by] = sortables[opts[:by]] if opts[:by]
|
90
94
|
objects(distkey.sort(opts))
|
91
95
|
end
|
data/lunar.gemspec
CHANGED
data/test/test_lunar.rb
CHANGED
@@ -67,6 +67,19 @@ class TestLunar < Test::Unit::TestCase
|
|
67
67
|
assert_equal %w{1003}, q(:q => '9000')
|
68
68
|
end
|
69
69
|
|
70
|
+
test "searching non-existent words" do
|
71
|
+
assert_equal [], q(:q => "ericson")
|
72
|
+
assert_equal [], q(:q => "ericson", :title => "apple")
|
73
|
+
assert_equal [], q(:q => "ericson", :description => "nokia")
|
74
|
+
assert_equal [], q(:q => "ericson", :description => "FooBar")
|
75
|
+
assert_equal [], q(:q => "ericson", :fuzzy => { :code => "a" })
|
76
|
+
assert_equal [], q(:q => "ericson", :price => 150..200)
|
77
|
+
end
|
78
|
+
|
79
|
+
test "sorting empty result sets" do
|
80
|
+
assert_equal [], Lunar.search(Gadget, :q => "ericson").sort(:by => :price)
|
81
|
+
end
|
82
|
+
|
70
83
|
test "fulltext searching with key value pairs" do
|
71
84
|
assert_equal %w{1001}, q(:q => 'apple', :tags => 'mobile')
|
72
85
|
assert_equal %w{1001}, q(:q => 'apple', :tags => 'smartphone')
|
@@ -178,4 +191,4 @@ class TestLunar < Test::Unit::TestCase
|
|
178
191
|
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mobile' })
|
179
192
|
end
|
180
193
|
end
|
181
|
-
end
|
194
|
+
end
|