picky 3.5.0 → 3.5.1

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.
Files changed (39) hide show
  1. data/lib/picky/bundle.rb +37 -4
  2. data/lib/picky/bundle_indexed.rb +12 -8
  3. data/lib/picky/bundle_indexing.rb +6 -26
  4. data/lib/picky/bundle_realtime.rb +26 -16
  5. data/lib/picky/category_indexing.rb +1 -3
  6. data/lib/picky/category_realtime.rb +1 -1
  7. data/lib/picky/character_substituters/west_european.rb +4 -4
  8. data/lib/picky/generators/partial/infix.rb +0 -47
  9. data/lib/picky/generators/partial/none.rb +0 -6
  10. data/lib/picky/generators/partial/substring.rb +0 -47
  11. data/lib/picky/generators/similarity/double_metaphone.rb +3 -3
  12. data/lib/picky/generators/similarity/metaphone.rb +3 -3
  13. data/lib/picky/generators/similarity/phonetic.rb +12 -24
  14. data/lib/picky/generators/similarity/soundex.rb +3 -3
  15. data/lib/picky/generators/weights/constant.rb +46 -0
  16. data/lib/picky/generators/weights/dynamic.rb +37 -0
  17. data/lib/picky/generators/weights/logarithmic.rb +0 -10
  18. data/lib/picky/generators/weights/runtime.rb +41 -0
  19. data/lib/picky/loader.rb +3 -3
  20. data/lib/picky/query/allocations.rb +2 -1
  21. data/lib/picky/query/tokens.rb +0 -10
  22. data/spec/lib/category_indexed_spec.rb +1 -1
  23. data/spec/lib/character_substituters/west_european_spec.rb +11 -13
  24. data/spec/lib/generators/partial/infix_spec.rb +161 -161
  25. data/spec/lib/generators/partial/none_spec.rb +3 -3
  26. data/spec/lib/generators/partial/postfix_spec.rb +109 -109
  27. data/spec/lib/generators/partial/substring_spec.rb +190 -190
  28. data/spec/lib/generators/similarity/double_metaphone_spec.rb +38 -38
  29. data/spec/lib/generators/similarity/metaphone_spec.rb +38 -38
  30. data/spec/lib/generators/similarity/soundex_spec.rb +38 -38
  31. data/spec/lib/generators/weights/constant_spec.rb +37 -0
  32. data/spec/lib/generators/weights/dynamic_spec.rb +27 -0
  33. data/spec/lib/generators/weights/logarithmic_spec.rb +10 -15
  34. data/spec/lib/indexed/bundle_spec.rb +3 -2
  35. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +8 -8
  36. data/spec/lib/indexing/bundle_spec.rb +5 -3
  37. data/spec/specific/dynamic_weights_spec.rb +44 -0
  38. metadata +36 -28
  39. 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
- 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
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
- 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
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
- 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
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