picky 3.5.0 → 3.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/picky/bundle.rb +37 -4
- data/lib/picky/bundle_indexed.rb +12 -8
- data/lib/picky/bundle_indexing.rb +6 -26
- data/lib/picky/bundle_realtime.rb +26 -16
- data/lib/picky/category_indexing.rb +1 -3
- data/lib/picky/category_realtime.rb +1 -1
- data/lib/picky/character_substituters/west_european.rb +4 -4
- data/lib/picky/generators/partial/infix.rb +0 -47
- data/lib/picky/generators/partial/none.rb +0 -6
- data/lib/picky/generators/partial/substring.rb +0 -47
- data/lib/picky/generators/similarity/double_metaphone.rb +3 -3
- data/lib/picky/generators/similarity/metaphone.rb +3 -3
- data/lib/picky/generators/similarity/phonetic.rb +12 -24
- data/lib/picky/generators/similarity/soundex.rb +3 -3
- data/lib/picky/generators/weights/constant.rb +46 -0
- data/lib/picky/generators/weights/dynamic.rb +37 -0
- data/lib/picky/generators/weights/logarithmic.rb +0 -10
- data/lib/picky/generators/weights/runtime.rb +41 -0
- data/lib/picky/loader.rb +3 -3
- data/lib/picky/query/allocations.rb +2 -1
- data/lib/picky/query/tokens.rb +0 -10
- data/spec/lib/category_indexed_spec.rb +1 -1
- data/spec/lib/character_substituters/west_european_spec.rb +11 -13
- data/spec/lib/generators/partial/infix_spec.rb +161 -161
- data/spec/lib/generators/partial/none_spec.rb +3 -3
- data/spec/lib/generators/partial/postfix_spec.rb +109 -109
- data/spec/lib/generators/partial/substring_spec.rb +190 -190
- data/spec/lib/generators/similarity/double_metaphone_spec.rb +38 -38
- data/spec/lib/generators/similarity/metaphone_spec.rb +38 -38
- data/spec/lib/generators/similarity/soundex_spec.rb +38 -38
- data/spec/lib/generators/weights/constant_spec.rb +37 -0
- data/spec/lib/generators/weights/dynamic_spec.rb +27 -0
- data/spec/lib/generators/weights/logarithmic_spec.rb +10 -15
- data/spec/lib/indexed/bundle_spec.rb +3 -2
- data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +8 -8
- data/spec/lib/indexing/bundle_spec.rb +5 -3
- data/spec/specific/dynamic_weights_spec.rb +44 -0
- metadata +36 -28
- data/lib/picky/generators/base.rb +0 -19
@@ -15,117 +15,117 @@ describe Picky::Generators::Partial::Postfix do
|
|
15
15
|
generator.from.should == 1
|
16
16
|
end
|
17
17
|
end
|
18
|
-
describe 'generate_from' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
18
|
+
# describe 'generate_from' do
|
19
|
+
# it 'should generate the right index' do
|
20
|
+
# generator.generate_from(florian: [1], flavia: [2]).should == {
|
21
|
+
# florian: [1],
|
22
|
+
# floria: [1],
|
23
|
+
# flori: [1],
|
24
|
+
# flor: [1],
|
25
|
+
# flo: [1],
|
26
|
+
# fl: [1, 2],
|
27
|
+
# f: [1, 2],
|
28
|
+
# flavia: [2],
|
29
|
+
# flavi: [2],
|
30
|
+
# flav: [2],
|
31
|
+
# fla: [2]
|
32
|
+
# }
|
33
|
+
# end
|
34
|
+
# it "should be fast" do
|
35
|
+
# performance_of { generator.generate_from(florian: [1], flavia: [2]) }.should < 0.0001
|
36
|
+
# end
|
37
|
+
# it "should handle duplicate ids" do
|
38
|
+
# generator.generate_from(flo: [1], fla: [1]).should == {
|
39
|
+
# flo: [1],
|
40
|
+
# fl: [1],
|
41
|
+
# f: [1],
|
42
|
+
# fla: [1]
|
43
|
+
# }
|
44
|
+
# end
|
45
|
+
# end
|
46
46
|
end
|
47
47
|
context 'specific negative from' do
|
48
|
-
describe 'negative from' do
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
|
-
context "large from" do
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
75
|
-
context 'specific positive from' do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
48
|
+
# describe 'negative from' do
|
49
|
+
# before(:each) do
|
50
|
+
# @generator = described_class.new from: -2
|
51
|
+
# end
|
52
|
+
# it 'should generate the right index' do
|
53
|
+
# @generator.generate_from(florian: [1], flavia: [2]).should == {
|
54
|
+
# florian: [1],
|
55
|
+
# floria: [1],
|
56
|
+
# flavia: [2],
|
57
|
+
# flavi: [2]
|
58
|
+
# }
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# context "large from" do
|
62
|
+
# before(:each) do
|
63
|
+
# @generator = described_class.new from: 10
|
64
|
+
# end
|
65
|
+
# describe 'generate_from' do
|
66
|
+
# it 'should generate the right index' do
|
67
|
+
# @generator.generate_from(florian: [1], :'01234567890' => [2] ).should == {
|
68
|
+
# :florian => [1],
|
69
|
+
# :'01234567890' => [2],
|
70
|
+
# :'0123456789' => [2]
|
71
|
+
# }
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
# context 'specific positive from' do
|
76
|
+
# before(:each) do
|
77
|
+
# @generator = described_class.new from: 4
|
78
|
+
# end
|
79
|
+
# describe 'to' do
|
80
|
+
# it 'should return the right value' do
|
81
|
+
# @generator.to.should == -1
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
# describe 'from' do
|
85
|
+
# it 'should return the right value' do
|
86
|
+
# @generator.from.should == 4
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
# describe 'generate_from' do
|
90
|
+
# it 'should generate the right index' do
|
91
|
+
# @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
92
|
+
# :florian => [1],
|
93
|
+
# :floria => [1],
|
94
|
+
# :flori => [1],
|
95
|
+
# :flor => [1],
|
96
|
+
# :flavia => [2],
|
97
|
+
# :flavi => [2],
|
98
|
+
# :flav => [2]
|
99
|
+
# }
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
# describe "a bigger example with disjunct symbols" do
|
103
|
+
# before(:each) do
|
104
|
+
# abc = ('A'..'Z').to_a + ('a'..'z').to_a
|
105
|
+
# @index = {}
|
106
|
+
# 52.times do |i|
|
107
|
+
# @index[abc.join.to_sym] = [i]
|
108
|
+
# character = abc.shift
|
109
|
+
# abc << character
|
110
|
+
# end
|
111
|
+
# end
|
112
|
+
# it "should be fast" do
|
113
|
+
# performance_of { @generator.generate_from(@index) }.should < 0.008
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
# describe "a bigger example with almost identical symbols" do
|
117
|
+
# before(:each) do
|
118
|
+
# abc = ('A'..'Z').to_a + ('a'..'z').to_a
|
119
|
+
# @index = {}
|
120
|
+
# 52.times do |i|
|
121
|
+
# @index[(abc.join + abc[i].to_s).to_sym] = [i]
|
122
|
+
# end
|
123
|
+
# end
|
124
|
+
# it "should be fast" do
|
125
|
+
# performance_of { @generator.generate_from(@index) }.should < 0.0045
|
126
|
+
# end
|
127
|
+
# end
|
128
|
+
# end
|
129
129
|
end
|
130
130
|
|
131
131
|
end
|
@@ -15,196 +15,196 @@ describe Picky::Generators::Partial::Substring do
|
|
15
15
|
generator.from.should == 1
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
47
|
-
context 'from set' do
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
18
|
+
# describe 'generate_from' do
|
19
|
+
# it 'should generate the right index' do
|
20
|
+
# generator.generate_from(florian: [1], flavia: [2]).should == {
|
21
|
+
# florian: [1],
|
22
|
+
# floria: [1],
|
23
|
+
# flori: [1],
|
24
|
+
# flor: [1],
|
25
|
+
# flo: [1],
|
26
|
+
# fl: [1, 2],
|
27
|
+
# f: [1, 2],
|
28
|
+
# flavia: [2],
|
29
|
+
# flavi: [2],
|
30
|
+
# flav: [2],
|
31
|
+
# fla: [2]
|
32
|
+
# }
|
33
|
+
# end
|
34
|
+
# it "should be fast" do
|
35
|
+
# performance_of { generator.generate_from(florian: [1], flavia: [2]) }.should < 0.0001
|
36
|
+
# end
|
37
|
+
# it "should handle duplicate ids" do
|
38
|
+
# generator.generate_from(flo: [1], fla: [1]).should == {
|
39
|
+
# flo: [1],
|
40
|
+
# fl: [1],
|
41
|
+
# f: [1],
|
42
|
+
# fla: [1]
|
43
|
+
# }
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
# context 'from set' do
|
48
|
+
# describe 'negative from' do
|
49
|
+
# before(:each) do
|
50
|
+
# @generator = described_class.new from: -2
|
51
|
+
# end
|
52
|
+
# it 'should generate the right index' do
|
53
|
+
# @generator.generate_from(florian: [1], flavia: [2]).should == {
|
54
|
+
# florian: [1],
|
55
|
+
# floria: [1],
|
56
|
+
# flavia: [2],
|
57
|
+
# flavi: [2]
|
58
|
+
# }
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
# context "large from" do
|
62
|
+
# before(:each) do
|
63
|
+
# @generator = described_class.new from: 10
|
64
|
+
# end
|
65
|
+
# describe 'generate_from' do
|
66
|
+
# it 'should generate the right index' do
|
67
|
+
# @generator.generate_from(florian: [1], :'01234567890' => [2] ).should == {
|
68
|
+
# :florian => [1],
|
69
|
+
# :'01234567890' => [2],
|
70
|
+
# :'0123456789' => [2]
|
71
|
+
# }
|
72
|
+
# end
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
# context 'default to' do
|
76
|
+
# before(:each) do
|
77
|
+
# @generator = described_class.new from: 4
|
78
|
+
# end
|
79
|
+
# describe 'to' do
|
80
|
+
# it 'should return the right value' do
|
81
|
+
# @generator.to.should == -1
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
# describe 'from' do
|
85
|
+
# it 'should return the right value' do
|
86
|
+
# @generator.from.should == 4
|
87
|
+
# end
|
88
|
+
# end
|
89
|
+
# describe 'generate_from' do
|
90
|
+
# it 'should generate the right index' do
|
91
|
+
# @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
92
|
+
# :florian => [1],
|
93
|
+
# :floria => [1],
|
94
|
+
# :flori => [1],
|
95
|
+
# :flor => [1],
|
96
|
+
# :flavia => [2],
|
97
|
+
# :flavi => [2],
|
98
|
+
# :flav => [2]
|
99
|
+
# }
|
100
|
+
# end
|
101
|
+
# end
|
102
|
+
# describe "a bigger example with disjunct symbols" do
|
103
|
+
# before(:each) do
|
104
|
+
# abc = ('A'..'Z').to_a + ('a'..'z').to_a
|
105
|
+
# @index = {}
|
106
|
+
# 52.times do |i|
|
107
|
+
# @index[abc.join.to_sym] = [i]
|
108
|
+
# character = abc.shift
|
109
|
+
# abc << character
|
110
|
+
# end
|
111
|
+
# end
|
112
|
+
# it "should be fast" do
|
113
|
+
# performance_of { @generator.generate_from(@index) }.should < 0.008
|
114
|
+
# end
|
115
|
+
# end
|
116
|
+
# describe "a bigger example with almost identical symbols" do
|
117
|
+
# before(:each) do
|
118
|
+
# abc = ('A'..'Z').to_a + ('a'..'z').to_a
|
119
|
+
# @index = {}
|
120
|
+
# 52.times do |i|
|
121
|
+
# @index[(abc.join + abc[i].to_s).to_sym] = [i]
|
122
|
+
# end
|
123
|
+
# end
|
124
|
+
# it "should be fast" do
|
125
|
+
# performance_of { @generator.generate_from(@index) }.should < 0.0045
|
126
|
+
# end
|
127
|
+
# end
|
128
|
+
# end
|
129
|
+
# context 'to set' do
|
130
|
+
# before(:each) do
|
131
|
+
# @generator = described_class.new from: 4, to: -2
|
132
|
+
# end
|
133
|
+
# describe 'to' do
|
134
|
+
# it 'should return the right value' do
|
135
|
+
# @generator.to.should == -2
|
136
|
+
# end
|
137
|
+
# end
|
138
|
+
# describe 'from' do
|
139
|
+
# it 'should return the right value' do
|
140
|
+
# @generator.from.should == 4
|
141
|
+
# end
|
142
|
+
# end
|
143
|
+
# describe 'generate_from' do
|
144
|
+
# it 'should generate the right index' do
|
145
|
+
# @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
146
|
+
# :floria => [1],
|
147
|
+
# :flori => [1],
|
148
|
+
# :flor => [1],
|
149
|
+
# :flavi => [2],
|
150
|
+
# :flav => [2]
|
151
|
+
# }
|
152
|
+
# end
|
153
|
+
# end
|
154
|
+
# end
|
155
|
+
# context 'to set' do
|
156
|
+
# before(:each) do
|
157
|
+
# @generator = described_class.new from: 4, to: 0
|
158
|
+
# end
|
159
|
+
# describe 'to' do
|
160
|
+
# it 'should return the right value' do
|
161
|
+
# @generator.to.should == 0
|
162
|
+
# end
|
163
|
+
# end
|
164
|
+
# describe 'from' do
|
165
|
+
# it 'should return the right value' do
|
166
|
+
# @generator.from.should == 4
|
167
|
+
# end
|
168
|
+
# end
|
169
|
+
# describe 'generate_from' do
|
170
|
+
# it 'should generate the right index' do
|
171
|
+
# @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
172
|
+
# :florian => [1],
|
173
|
+
# :floria => [1],
|
174
|
+
# :flori => [1],
|
175
|
+
# :flor => [1],
|
176
|
+
# :flavia => [2],
|
177
|
+
# :flavi => [2],
|
178
|
+
# :flav => [2]
|
179
|
+
# }
|
180
|
+
# end
|
181
|
+
# end
|
182
|
+
# end
|
183
|
+
# context 'to set, negative from' do
|
184
|
+
# before(:each) do
|
185
|
+
# @generator = described_class.new from: -3, to: -2
|
186
|
+
# end
|
187
|
+
# describe 'to' do
|
188
|
+
# it 'should return the right value' do
|
189
|
+
# @generator.to.should == -2
|
190
|
+
# end
|
191
|
+
# end
|
192
|
+
# describe 'from' do
|
193
|
+
# it 'should return the right value' do
|
194
|
+
# @generator.from.should == -3
|
195
|
+
# end
|
196
|
+
# end
|
197
|
+
# describe 'generate_from' do
|
198
|
+
# it 'should generate the right index' do
|
199
|
+
# @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
|
200
|
+
# :floria => [1],
|
201
|
+
# :flori => [1],
|
202
|
+
# :flavi => [2],
|
203
|
+
# :flav => [2]
|
204
|
+
# }
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
# end
|
208
208
|
end
|
209
209
|
|
210
210
|
end
|