lunar 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -1
- data/LICENSE +1 -1
- data/README.markdown +116 -0
- data/Rakefile +6 -5
- data/VERSION +1 -1
- data/lib/lunar.rb +112 -24
- data/lib/lunar/connection.rb +51 -0
- data/lib/lunar/fuzzy_matches.rb +24 -0
- data/lib/lunar/fuzzy_word.rb +2 -2
- data/lib/lunar/index.rb +200 -94
- data/lib/lunar/keyword_matches.rb +32 -0
- data/lib/lunar/lunar_nest.rb +19 -0
- data/lib/lunar/range_matches.rb +28 -0
- data/lib/lunar/result_set.rb +85 -28
- data/lib/lunar/scoring.rb +4 -2
- data/lib/lunar/stopwords.rb +15 -0
- data/lib/lunar/words.rb +6 -3
- data/lunar.gemspec +31 -60
- data/test/helper.rb +4 -5
- data/test/test_fuzzy_indexing.rb +105 -0
- data/test/test_index.rb +150 -0
- data/test/test_lunar.rb +178 -1
- data/test/test_lunar_fuzzy_word.rb +4 -4
- data/test/test_lunar_nest.rb +46 -0
- data/test/{test_lunar_scoring.rb → test_scoring.rb} +5 -5
- metadata +72 -68
- data/.document +0 -5
- data/DATA +0 -41
- data/README.md +0 -80
- data/examples/ohm.rb +0 -40
- data/lib/lunar/search.rb +0 -68
- data/lib/lunar/sets.rb +0 -86
- data/test/test_lunar_fuzzy.rb +0 -118
- data/test/test_lunar_index.rb +0 -191
- data/test/test_lunar_search.rb +0 -261
- data/test/test_sets.rb +0 -48
- data/vendor/nest/nest.rb +0 -7
- data/vendor/redis/.gitignore +0 -9
- data/vendor/redis/LICENSE +0 -20
- data/vendor/redis/README.markdown +0 -120
- data/vendor/redis/Rakefile +0 -75
- data/vendor/redis/benchmarking/logging.rb +0 -62
- data/vendor/redis/benchmarking/pipeline.rb +0 -44
- data/vendor/redis/benchmarking/speed.rb +0 -21
- data/vendor/redis/benchmarking/suite.rb +0 -24
- data/vendor/redis/benchmarking/worker.rb +0 -71
- data/vendor/redis/bin/distredis +0 -33
- data/vendor/redis/examples/basic.rb +0 -15
- data/vendor/redis/examples/dist_redis.rb +0 -43
- data/vendor/redis/examples/incr-decr.rb +0 -17
- data/vendor/redis/examples/list.rb +0 -26
- data/vendor/redis/examples/pubsub.rb +0 -25
- data/vendor/redis/examples/sets.rb +0 -36
- data/vendor/redis/lib/edis.rb +0 -3
- data/vendor/redis/lib/redis.rb +0 -496
- data/vendor/redis/lib/redis/client.rb +0 -265
- data/vendor/redis/lib/redis/dist_redis.rb +0 -118
- data/vendor/redis/lib/redis/distributed.rb +0 -460
- data/vendor/redis/lib/redis/hash_ring.rb +0 -131
- data/vendor/redis/lib/redis/pipeline.rb +0 -13
- data/vendor/redis/lib/redis/raketasks.rb +0 -1
- data/vendor/redis/lib/redis/subscribe.rb +0 -79
- data/vendor/redis/profile.rb +0 -22
- data/vendor/redis/tasks/redis.tasks.rb +0 -140
- data/vendor/redis/test/db/.gitignore +0 -1
- data/vendor/redis/test/distributed_test.rb +0 -1131
- data/vendor/redis/test/redis_test.rb +0 -1134
- data/vendor/redis/test/test.conf +0 -8
- data/vendor/redis/test/test_helper.rb +0 -113
data/test/test_index.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class IndexTest < Test::Unit::TestCase
|
4
|
+
class Gadget < Struct.new(:id)
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "indexing texts" do
|
8
|
+
def nest(word)
|
9
|
+
Lunar.nest[:Gadget][:title][Lunar.metaphone(word)]
|
10
|
+
end
|
11
|
+
|
12
|
+
test "with non-repeating words" do
|
13
|
+
ret = Lunar.index :Gadget do |i|
|
14
|
+
i.id 1001
|
15
|
+
i.text :title, 'apple iphone 3GS smartphone'
|
16
|
+
end
|
17
|
+
|
18
|
+
assert_equal ['1001'], nest('apple').zrangebyscore(1, 1)
|
19
|
+
assert_equal ['1001'], nest('iphone').zrangebyscore(1, 1)
|
20
|
+
assert_equal ['1001'], nest('3gs').zrangebyscore(1, 1)
|
21
|
+
assert_equal ['1001'], nest('smartphone').zrangebyscore(1, 1)
|
22
|
+
|
23
|
+
assert_equal %w{APL IFN KS SMRTFN},
|
24
|
+
Lunar.nest[:Gadget][:Metaphones][1001][:title].smembers.sort
|
25
|
+
end
|
26
|
+
|
27
|
+
test "deleting non-repeating words scenario" do
|
28
|
+
ret = Lunar.index :Gadget do |i|
|
29
|
+
i.id 1001
|
30
|
+
i.text :title, 'apple iphone 3GS smartphone'
|
31
|
+
end
|
32
|
+
|
33
|
+
Lunar.delete(:Gadget, 1001)
|
34
|
+
|
35
|
+
assert_equal 0, nest('apple').zcard
|
36
|
+
assert_equal 0, nest('iphone').zcard
|
37
|
+
assert_equal 0, nest('3gs').zcard
|
38
|
+
assert_equal 0, nest('smartphone').zcard
|
39
|
+
|
40
|
+
assert_equal 0, Lunar.nest[:Gadget][1001][:title].scard
|
41
|
+
end
|
42
|
+
|
43
|
+
test "with multiple word instances and stopwords" do
|
44
|
+
Lunar.index :Gadget do |i|
|
45
|
+
i.id 1001
|
46
|
+
i.text :title, 'count of monte cristo will count to 100'
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_equal ['1001'], nest('count').zrangebyscore(2, 2)
|
50
|
+
assert_equal ['1001'], nest('monte').zrangebyscore(1, 1)
|
51
|
+
assert_equal ['1001'], nest('cristo').zrangebyscore(1, 1)
|
52
|
+
assert_equal ['1001'], nest('100').zrangebyscore(1, 1)
|
53
|
+
|
54
|
+
assert nest('of').zrange(0, -1).empty?
|
55
|
+
assert nest('to').zrange(0, -1).empty?
|
56
|
+
assert nest('will').zrange(0, -1).empty?
|
57
|
+
end
|
58
|
+
|
59
|
+
test "deleting multiple word instances scenario" do
|
60
|
+
Lunar.index :Gadget do |i|
|
61
|
+
i.id 1001
|
62
|
+
i.text :title, 'count of monte cristo will count to 100'
|
63
|
+
end
|
64
|
+
|
65
|
+
Lunar.delete(:Gadget, 1001)
|
66
|
+
|
67
|
+
assert_equal 0, nest('count').zcard
|
68
|
+
assert_equal 0, nest('monte').zcard
|
69
|
+
assert_equal 0, nest('cristo').zcard
|
70
|
+
assert_equal 0, nest('100').zcard
|
71
|
+
|
72
|
+
assert_nil Lunar.nest[:Gadget][1001][:title].get
|
73
|
+
end
|
74
|
+
|
75
|
+
test "re-indexing" do
|
76
|
+
Lunar.index :Gadget do |i|
|
77
|
+
i.id 1001
|
78
|
+
i.text :title, 'apple iphone 3GS smartphone'
|
79
|
+
end
|
80
|
+
|
81
|
+
Lunar.index :Gadget do |i|
|
82
|
+
i.id 1001
|
83
|
+
i.text :title, 'apple iphone 3G'
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_equal ['1001'], nest('apple').zrangebyscore(1, 1)
|
87
|
+
assert_equal ['1001'], nest('iphone').zrangebyscore(1, 1)
|
88
|
+
assert_equal ['1001'], nest('3g').zrangebyscore(1, 1)
|
89
|
+
|
90
|
+
assert nest('3gs').zrange(0, -1).empty?
|
91
|
+
assert nest('smartphone').zrange(0, -1).empty?
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "indexing numbers" do
|
96
|
+
test "works for integers and floats" do
|
97
|
+
Lunar.index :Gadget do |i|
|
98
|
+
i.id 1001
|
99
|
+
i.number :price, 200
|
100
|
+
i.number :score, 25.5
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_equal '200', Lunar.nest[:Gadget][:Numbers][:price].zscore(1001)
|
104
|
+
assert_equal '25.5', Lunar.nest[:Gadget][:Numbers][:score].zscore(1001)
|
105
|
+
end
|
106
|
+
|
107
|
+
test "allows deletion" do
|
108
|
+
Lunar.index :Gadget do |i|
|
109
|
+
i.id 1001
|
110
|
+
i.number :price, 200
|
111
|
+
i.number :score, 25.5
|
112
|
+
end
|
113
|
+
|
114
|
+
Lunar.delete :Gadget, 1001
|
115
|
+
|
116
|
+
assert_nil Lunar.nest[:Gadget][:Numbers][:price].zrank(1001)
|
117
|
+
assert_nil Lunar.nest[:Gadget][:Numbers][:score].zrank(1001)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "sortable fields" do
|
122
|
+
test "works for integers, floats, strings" do
|
123
|
+
Lunar.index :Gadget do |i|
|
124
|
+
i.id 1001
|
125
|
+
i.sortable :name, 'iphone'
|
126
|
+
i.sortable :price, 200
|
127
|
+
i.sortable :score, 25.5
|
128
|
+
end
|
129
|
+
|
130
|
+
assert_equal 'iphone', Lunar.nest[:Gadget][:Sortables][1001][:name].get
|
131
|
+
assert_equal '200', Lunar.nest[:Gadget][:Sortables][1001][:price].get
|
132
|
+
assert_equal '25.5', Lunar.nest[:Gadget][:Sortables][1001][:score].get
|
133
|
+
end
|
134
|
+
|
135
|
+
test "deletes sortable fields" do
|
136
|
+
Lunar.index :Gadget do |i|
|
137
|
+
i.id 1001
|
138
|
+
i.sortable :name, 'iphone'
|
139
|
+
i.sortable :price, 200
|
140
|
+
i.sortable :score, 25.5
|
141
|
+
end
|
142
|
+
|
143
|
+
Lunar.delete :Gadget, 1001
|
144
|
+
|
145
|
+
assert_nil Lunar.nest[:Gadget][1001][:name].get
|
146
|
+
assert_nil Lunar.nest[:Gadget][1001][:price].get
|
147
|
+
assert_nil Lunar.nest[:Gadget][1001][:score].get
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
data/test/test_lunar.rb
CHANGED
@@ -1,4 +1,181 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestLunar < Test::Unit::TestCase
|
4
|
-
|
4
|
+
class Gadget < Struct.new(:id)
|
5
|
+
def self.[](id)
|
6
|
+
new(id)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
context "an index of some gadgets" do
|
11
|
+
setup do
|
12
|
+
Lunar.index Gadget do |i|
|
13
|
+
i.id 1001
|
14
|
+
i.text :title, 'apple iphone 3GS smartphone'
|
15
|
+
i.text :tags, 'mobile smartphone apple'
|
16
|
+
i.number :price, 200
|
17
|
+
i.number :score, 35.5
|
18
|
+
i.fuzzy :code, 'apple iphone mobile'
|
19
|
+
|
20
|
+
i.sortable :price, 200
|
21
|
+
i.sortable :score, 35.5
|
22
|
+
i.sortable :title, 'apple iphone 3GS'
|
23
|
+
end
|
24
|
+
|
25
|
+
Lunar.index Gadget do |i|
|
26
|
+
i.id 1002
|
27
|
+
i.text :title, 'nokia N95 Symbian smartphone'
|
28
|
+
i.text :tags, 'mobile smartphone nokia'
|
29
|
+
i.number :price, 150
|
30
|
+
i.number :score, 20.5
|
31
|
+
i.fuzzy :code, 'nokia n95 mobile'
|
32
|
+
|
33
|
+
i.sortable :price, 150
|
34
|
+
i.sortable :score, 20.5
|
35
|
+
i.sortable :title, 'nokia N95 Symbian smartphone'
|
36
|
+
end
|
37
|
+
|
38
|
+
Lunar.index Gadget do |i|
|
39
|
+
i.id 1003
|
40
|
+
i.text :title, 'blackberry bold 9000 smartphone'
|
41
|
+
i.text :tags, 'mobile smartphone blackberry'
|
42
|
+
i.number :price, 170
|
43
|
+
i.number :score, 25.5
|
44
|
+
i.fuzzy :code, 'blackberry bold mobile'
|
45
|
+
|
46
|
+
i.sortable :price, 170
|
47
|
+
i.sortable :score, 25.5
|
48
|
+
i.sortable :title, 'blackberry bold 9000 smartphone'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def q(options)
|
53
|
+
Lunar.search(Gadget, options).map(&:id)
|
54
|
+
end
|
55
|
+
|
56
|
+
test "all kinds of fulltext searching" do
|
57
|
+
assert_equal %w{1001}, q(:q => 'apple')
|
58
|
+
assert_equal %w{1001}, q(:q => 'iphone')
|
59
|
+
assert_equal %w{1001}, q(:q => '3gs')
|
60
|
+
assert_equal %w{1001 1002 1003}, q(:q => 'smartphone')
|
61
|
+
assert_equal %w{1001 1002 1003}, q(:q => 'mobile')
|
62
|
+
assert_equal %w{1002}, q(:q => 'nokia')
|
63
|
+
assert_equal %w{1002}, q(:q => 'n95')
|
64
|
+
assert_equal %w{1002}, q(:q => 'symbian')
|
65
|
+
assert_equal %w{1003}, q(:q => 'blackberry')
|
66
|
+
assert_equal %w{1003}, q(:q => 'bold')
|
67
|
+
assert_equal %w{1003}, q(:q => '9000')
|
68
|
+
end
|
69
|
+
|
70
|
+
test "fulltext searching with key value pairs" do
|
71
|
+
assert_equal %w{1001}, q(:q => 'apple', :tags => 'mobile')
|
72
|
+
assert_equal %w{1001}, q(:q => 'apple', :tags => 'smartphone')
|
73
|
+
assert_equal %w{1001}, q(:q => 'apple', :tags => 'apple')
|
74
|
+
|
75
|
+
assert_equal %w{1001 1002 1003}, q(:q => 'mobile', :tags => 'smartphone')
|
76
|
+
end
|
77
|
+
|
78
|
+
test "fulltext + keyword searching with range matching" do
|
79
|
+
assert_equal %w{1001}, q(:q => 'mobile', :tags => 'smartphone', :price => 200..200)
|
80
|
+
assert_equal %w{1002}, q(:q => 'mobile', :tags => 'smartphone', :price => 150..150)
|
81
|
+
assert_equal %w{1003}, q(:q => 'mobile', :tags => 'smartphone', :price => 170..170)
|
82
|
+
|
83
|
+
assert_equal %w{1001 1002 1003}, q(:price => 150..200)
|
84
|
+
end
|
85
|
+
|
86
|
+
test "searching one key => value pair" do
|
87
|
+
assert_equal %w{1001}, q(:title => 'apple')
|
88
|
+
assert_equal %w{1001}, q(:title => 'iphone')
|
89
|
+
assert_equal %w{1001}, q(:title => '3GS')
|
90
|
+
assert_equal %w{1001 1002 1003}, q(:title => 'smartphone')
|
91
|
+
end
|
92
|
+
|
93
|
+
test "searching multiple key => value pairs" do
|
94
|
+
assert_equal %w{1001}, q(:title => 'apple', :tags => 'mobile')
|
95
|
+
assert_equal %w{1001}, q(:title => 'apple', :tags => 'smartphone')
|
96
|
+
assert_equal %w{1001}, q(:title => 'apple', :tags => 'apple')
|
97
|
+
|
98
|
+
assert_equal %w{1001 1002 1003}, q(:title => 'smartphone', :tags => 'mobile')
|
99
|
+
assert_equal %w{1001 1002 1003}, q(:title => 'smartphone', :tags => 'smartphone')
|
100
|
+
assert_equal %w{1001}, q(:title => 'smartphone', :tags => 'apple')
|
101
|
+
end
|
102
|
+
|
103
|
+
test "sorting by price" do
|
104
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort_by(:price, :order => 'ASC')
|
105
|
+
assert_equal %w{1002 1003 1001}, r.map(&:id)
|
106
|
+
|
107
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort_by(:price, :order => 'DESC')
|
108
|
+
assert_equal %w{1001 1003 1002}, r.map(&:id)
|
109
|
+
|
110
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort(:by => :price, :order => 'ASC')
|
111
|
+
assert_equal %w{1002 1003 1001}, r.map(&:id)
|
112
|
+
|
113
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort(:by => :price, :order => 'DESC')
|
114
|
+
assert_equal %w{1001 1003 1002}, r.map(&:id)
|
115
|
+
end
|
116
|
+
|
117
|
+
test "sorting by score" do
|
118
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort_by(:score, :order => 'ASC')
|
119
|
+
assert_equal %w{1002 1003 1001}, r.map(&:id)
|
120
|
+
|
121
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort_by(:score, :order => 'DESC')
|
122
|
+
assert_equal %w{1001 1003 1002}, r.map(&:id)
|
123
|
+
|
124
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort(:by => :score, :order => 'ASC')
|
125
|
+
assert_equal %w{1002 1003 1001}, r.map(&:id)
|
126
|
+
|
127
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort(:by => :score, :order => 'DESC')
|
128
|
+
assert_equal %w{1001 1003 1002}, r.map(&:id)
|
129
|
+
end
|
130
|
+
|
131
|
+
test "sorting by title" do
|
132
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort_by(:title, :order => 'ALPHA ASC')
|
133
|
+
assert_equal %w{1001 1003 1002}, r.map(&:id)
|
134
|
+
|
135
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort_by(:title, :order => 'ALPHA DESC')
|
136
|
+
assert_equal %w{1002 1003 1001}, r.map(&:id)
|
137
|
+
|
138
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort(:by => :title, :order => 'ALPHA ASC')
|
139
|
+
assert_equal %w{1001 1003 1002}, r.map(&:id)
|
140
|
+
|
141
|
+
r = Lunar.search(Gadget, :q => 'smartphone').sort(:by => :title, :order => 'ALPHA DESC')
|
142
|
+
assert_equal %w{1002 1003 1001}, r.map(&:id)
|
143
|
+
end
|
144
|
+
|
145
|
+
test "fuzzy matching on code apple iphone" do
|
146
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'a' })
|
147
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'ap' })
|
148
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'app' })
|
149
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'appl' })
|
150
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'apple' })
|
151
|
+
|
152
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'i' })
|
153
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'ip' })
|
154
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'iph' })
|
155
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'ipho' })
|
156
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'iphon' })
|
157
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'iphone' })
|
158
|
+
|
159
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'a i' })
|
160
|
+
assert_equal %w{1001}, q(:fuzzy => { :code => 'app iph' })
|
161
|
+
end
|
162
|
+
|
163
|
+
test "fuzzy matching on code mobile" do
|
164
|
+
assert_equal %w{1001 1002 1003}, q(:fuzzy => { :code => 'm' })
|
165
|
+
assert_equal %w{1001 1002 1003}, q(:fuzzy => { :code => 'mo' })
|
166
|
+
assert_equal %w{1001 1002 1003}, q(:fuzzy => { :code => 'mob' })
|
167
|
+
assert_equal %w{1001 1002 1003}, q(:fuzzy => { :code => 'mobi' })
|
168
|
+
assert_equal %w{1001 1002 1003}, q(:fuzzy => { :code => 'mobil' })
|
169
|
+
assert_equal %w{1001 1002 1003}, q(:fuzzy => { :code => 'mobile' })
|
170
|
+
end
|
171
|
+
|
172
|
+
test "fuzzy matching on code mobile with keywords: apple" do
|
173
|
+
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'm' })
|
174
|
+
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mo' })
|
175
|
+
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mob' })
|
176
|
+
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mobi' })
|
177
|
+
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mobil' })
|
178
|
+
assert_equal %w{1001}, q(:q => 'apple', :fuzzy => { :code => 'mobile' })
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -5,10 +5,10 @@ class LunarFuzzyWordTest < Test::Unit::TestCase
|
|
5
5
|
setup do
|
6
6
|
@w = Lunar::FuzzyWord.new('dictionary')
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
should "have d, di, ... dictionary as it's partials" do
|
10
|
-
assert_equal ['d', 'di', 'dic', 'dict', 'dicti', 'dictio',
|
11
|
-
'diction', 'dictiona', 'dictionar', 'dictionary'], @w.partials
|
10
|
+
assert_equal ['d', 'di', 'dic', 'dict', 'dicti', 'dictio',
|
11
|
+
'diction', 'dictiona', 'dictionar', 'dictionary'], @w.partials
|
12
12
|
end
|
13
13
|
end
|
14
|
-
end
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
class LunarNestTest < Test::Unit::TestCase
|
4
|
+
test "retrieving keys for a pattern" do
|
5
|
+
Lunar.redis.set("Foo:1:Bar", 1)
|
6
|
+
Lunar.redis.set("Foo:2:Bar", 2)
|
7
|
+
|
8
|
+
nest = Lunar::LunarNest.new("Foo", Lunar.redis)['*']["Bar"]
|
9
|
+
|
10
|
+
assert_equal ['Foo:1:Bar', 'Foo:2:Bar'], nest.keys.sort
|
11
|
+
end
|
12
|
+
|
13
|
+
test "retrieving keys and their matches" do
|
14
|
+
Lunar.redis.set("Foo:1:Bar", 1)
|
15
|
+
Lunar.redis.set("Foo:2:Bar", 2)
|
16
|
+
|
17
|
+
nest = Lunar::LunarNest.new("Foo", Lunar.redis)['*']["Bar"]
|
18
|
+
|
19
|
+
matches = []
|
20
|
+
|
21
|
+
nest.matches.each do |key, m|
|
22
|
+
matches << m
|
23
|
+
end
|
24
|
+
|
25
|
+
assert_equal ['1', '2'], matches.sort
|
26
|
+
end
|
27
|
+
|
28
|
+
test "retrieving keys and their matches when more than one *" do
|
29
|
+
Lunar.redis.set("Foo:1:Bar:3:Baz", 1)
|
30
|
+
Lunar.redis.set("Foo:2:Bar:4:Baz", 2)
|
31
|
+
|
32
|
+
nest = Lunar::LunarNest.new("Foo", Lunar.redis)['*']["Bar"]["*"]["Baz"]
|
33
|
+
|
34
|
+
matches1 = []
|
35
|
+
matches2 = []
|
36
|
+
|
37
|
+
nest.matches.each do |key, m1, m2|
|
38
|
+
matches1 << m1
|
39
|
+
matches2 << m2
|
40
|
+
end
|
41
|
+
|
42
|
+
assert_equal ['1', '2'], matches1.sort
|
43
|
+
assert_equal ['3', '4'], matches2.sort
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class LunarScoringTest < Test::Unit::TestCase
|
4
4
|
describe "scores of 'the quick brown fox jumps over the lazy dog'" do
|
5
5
|
should "return a hash of the words with score 1 except the, with score 2" do
|
6
6
|
scoring = Lunar::Scoring.new("the quick brown fox jumps over the lazy dog")
|
7
|
-
assert_equal
|
7
|
+
assert_equal 0, scoring.scores["the"]
|
8
8
|
assert_equal 1, scoring.scores["quick"]
|
9
9
|
assert_equal 1, scoring.scores["brown"]
|
10
10
|
assert_equal 1, scoring.scores["fox"]
|
@@ -18,10 +18,10 @@ class LunarScoringTest < Test::Unit::TestCase
|
|
18
18
|
describe "scores of 'tHe qUick bRowN the quick brown THE QUICK BROWN'" do
|
19
19
|
should "return a hash of each of the words the quick brown with score 3" do
|
20
20
|
scoring = Lunar::Scoring.new('tHe qUick bRowN the quick brown THE QUICK BROWN')
|
21
|
-
assert_equal
|
21
|
+
assert_equal 0, scoring.scores['the']
|
22
22
|
assert_equal 3, scoring.scores['quick']
|
23
23
|
assert_equal 3, scoring.scores['brown']
|
24
|
-
end
|
24
|
+
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe 'scores of apple macbook pro 17"' do
|
@@ -33,4 +33,4 @@ class LunarScoringTest < Test::Unit::TestCase
|
|
33
33
|
assert_equal 1, scoring.scores['17']
|
34
34
|
end
|
35
35
|
end
|
36
|
-
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lunar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Cyril David
|
@@ -9,30 +14,62 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-21 00:00:00 +08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
name: redis
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 2.0.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: nest
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 0
|
44
|
+
- 4
|
45
|
+
version: 0.0.4
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: text
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
23
57
|
version: "0"
|
24
|
-
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
25
60
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
name: contest
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
30
64
|
requirements:
|
31
65
|
- - ">="
|
32
66
|
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
33
69
|
version: "0"
|
34
|
-
|
35
|
-
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id004
|
72
|
+
description: Features full text searching via metaphones, range querying for numbers, fuzzy searching and sorting based on customer fields
|
36
73
|
email: cyx.ucron@gmail.com
|
37
74
|
executables: []
|
38
75
|
|
@@ -40,66 +77,33 @@ extensions: []
|
|
40
77
|
|
41
78
|
extra_rdoc_files:
|
42
79
|
- LICENSE
|
43
|
-
- README.
|
80
|
+
- README.markdown
|
44
81
|
files:
|
45
|
-
- .document
|
46
82
|
- .gitignore
|
47
|
-
- DATA
|
48
83
|
- LICENSE
|
49
|
-
- README.
|
84
|
+
- README.markdown
|
50
85
|
- Rakefile
|
51
86
|
- VERSION
|
52
|
-
- examples/ohm.rb
|
53
87
|
- lib/lunar.rb
|
88
|
+
- lib/lunar/connection.rb
|
89
|
+
- lib/lunar/fuzzy_matches.rb
|
54
90
|
- lib/lunar/fuzzy_word.rb
|
55
91
|
- lib/lunar/index.rb
|
92
|
+
- lib/lunar/keyword_matches.rb
|
93
|
+
- lib/lunar/lunar_nest.rb
|
94
|
+
- lib/lunar/range_matches.rb
|
56
95
|
- lib/lunar/result_set.rb
|
57
96
|
- lib/lunar/scoring.rb
|
58
|
-
- lib/lunar/
|
59
|
-
- lib/lunar/sets.rb
|
97
|
+
- lib/lunar/stopwords.rb
|
60
98
|
- lib/lunar/words.rb
|
61
99
|
- lunar.gemspec
|
62
100
|
- test/helper.rb
|
101
|
+
- test/test_fuzzy_indexing.rb
|
102
|
+
- test/test_index.rb
|
63
103
|
- test/test_lunar.rb
|
64
|
-
- test/test_lunar_fuzzy.rb
|
65
104
|
- test/test_lunar_fuzzy_word.rb
|
66
|
-
- test/
|
67
|
-
- test/
|
68
|
-
- test/test_lunar_search.rb
|
69
|
-
- test/test_sets.rb
|
70
|
-
- vendor/nest/nest.rb
|
71
|
-
- vendor/redis/.gitignore
|
72
|
-
- vendor/redis/LICENSE
|
73
|
-
- vendor/redis/README.markdown
|
74
|
-
- vendor/redis/Rakefile
|
75
|
-
- vendor/redis/benchmarking/logging.rb
|
76
|
-
- vendor/redis/benchmarking/pipeline.rb
|
77
|
-
- vendor/redis/benchmarking/speed.rb
|
78
|
-
- vendor/redis/benchmarking/suite.rb
|
79
|
-
- vendor/redis/benchmarking/worker.rb
|
80
|
-
- vendor/redis/bin/distredis
|
81
|
-
- vendor/redis/examples/basic.rb
|
82
|
-
- vendor/redis/examples/dist_redis.rb
|
83
|
-
- vendor/redis/examples/incr-decr.rb
|
84
|
-
- vendor/redis/examples/list.rb
|
85
|
-
- vendor/redis/examples/pubsub.rb
|
86
|
-
- vendor/redis/examples/sets.rb
|
87
|
-
- vendor/redis/lib/edis.rb
|
88
|
-
- vendor/redis/lib/redis.rb
|
89
|
-
- vendor/redis/lib/redis/client.rb
|
90
|
-
- vendor/redis/lib/redis/dist_redis.rb
|
91
|
-
- vendor/redis/lib/redis/distributed.rb
|
92
|
-
- vendor/redis/lib/redis/hash_ring.rb
|
93
|
-
- vendor/redis/lib/redis/pipeline.rb
|
94
|
-
- vendor/redis/lib/redis/raketasks.rb
|
95
|
-
- vendor/redis/lib/redis/subscribe.rb
|
96
|
-
- vendor/redis/profile.rb
|
97
|
-
- vendor/redis/tasks/redis.tasks.rb
|
98
|
-
- vendor/redis/test/db/.gitignore
|
99
|
-
- vendor/redis/test/distributed_test.rb
|
100
|
-
- vendor/redis/test/redis_test.rb
|
101
|
-
- vendor/redis/test/test.conf
|
102
|
-
- vendor/redis/test/test_helper.rb
|
105
|
+
- test/test_lunar_nest.rb
|
106
|
+
- test/test_scoring.rb
|
103
107
|
has_rdoc: true
|
104
108
|
homepage: http://github.com/sinefunc/lunar
|
105
109
|
licenses: []
|
@@ -113,28 +117,28 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
117
|
requirements:
|
114
118
|
- - ">="
|
115
119
|
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
116
122
|
version: "0"
|
117
|
-
version:
|
118
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
124
|
requirements:
|
120
125
|
- - ">="
|
121
126
|
- !ruby/object:Gem::Version
|
127
|
+
segments:
|
128
|
+
- 0
|
122
129
|
version: "0"
|
123
|
-
version:
|
124
130
|
requirements: []
|
125
131
|
|
126
132
|
rubyforge_project:
|
127
|
-
rubygems_version: 1.3.
|
133
|
+
rubygems_version: 1.3.6
|
128
134
|
signing_key:
|
129
135
|
specification_version: 3
|
130
|
-
summary:
|
136
|
+
summary: A redis based full text search engine
|
131
137
|
test_files:
|
132
138
|
- test/helper.rb
|
139
|
+
- test/test_fuzzy_indexing.rb
|
140
|
+
- test/test_index.rb
|
133
141
|
- test/test_lunar.rb
|
134
|
-
- test/test_lunar_fuzzy.rb
|
135
142
|
- test/test_lunar_fuzzy_word.rb
|
136
|
-
- test/
|
137
|
-
- test/
|
138
|
-
- test/test_lunar_search.rb
|
139
|
-
- test/test_sets.rb
|
140
|
-
- examples/ohm.rb
|
143
|
+
- test/test_lunar_nest.rb
|
144
|
+
- test/test_scoring.rb
|