picky 3.1.0 → 3.1.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/backends/file/basic.rb +10 -80
  2. data/lib/picky/backends/file/json.rb +56 -15
  3. data/lib/picky/backends/file.rb +62 -0
  4. data/lib/picky/backends/memory/basic.rb +111 -0
  5. data/lib/picky/backends/memory/json.rb +41 -0
  6. data/lib/picky/backends/{file → memory}/marshal.rb +4 -1
  7. data/lib/picky/backends/{file → memory}/text.rb +5 -1
  8. data/lib/picky/backends/memory.rb +16 -6
  9. data/lib/picky/backends/redis/{float_hash.rb → float.rb} +1 -1
  10. data/lib/picky/backends/redis/{list_hash.rb → list.rb} +1 -1
  11. data/lib/picky/backends/redis/{string_hash.rb → string.rb} +1 -1
  12. data/lib/picky/backends/redis.rb +16 -6
  13. data/lib/picky/bundle.rb +5 -2
  14. data/lib/picky/category.rb +1 -1
  15. data/lib/picky/cores.rb +7 -0
  16. data/lib/picky/extensions/symbol.rb +22 -0
  17. data/lib/picky/generators/partial/infix.rb +93 -0
  18. data/lib/picky/generators/partial/substring.rb +2 -2
  19. data/lib/picky/indexes_indexing.rb +2 -0
  20. data/lib/picky/indexing/bundle.rb +1 -1
  21. data/lib/picky/loader.rb +11 -6
  22. data/lib/picky/migrations/from_30_to_31.rb +2 -2
  23. data/lib/picky/query/allocation.rb +1 -0
  24. data/lib/picky/query/combinations.rb +3 -1
  25. data/spec/lib/backends/{file → memory}/basic_spec.rb +3 -3
  26. data/spec/lib/backends/{file → memory}/json_spec.rb +3 -3
  27. data/spec/lib/backends/{file → memory}/marshal_spec.rb +3 -3
  28. data/spec/lib/backends/{file → memory}/text_spec.rb +1 -1
  29. data/spec/lib/backends/memory_spec.rb +4 -4
  30. data/spec/lib/backends/redis/{float_hash_spec.rb → float_spec.rb} +2 -2
  31. data/spec/lib/backends/redis/{list_hash_spec.rb → list_spec.rb} +2 -2
  32. data/spec/lib/backends/redis/{string_hash_spec.rb → string_spec.rb} +2 -2
  33. data/spec/lib/backends/redis_spec.rb +4 -4
  34. data/spec/lib/bundle_spec.rb +27 -0
  35. data/spec/lib/extensions/symbol_spec.rb +237 -1
  36. data/spec/lib/generators/partial/infix_spec.rb +233 -0
  37. data/spec/lib/indexed/memory_spec.rb +8 -8
  38. data/spec/lib/query/allocation_spec.rb +7 -5
  39. metadata +30 -22
@@ -0,0 +1,233 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Generators::Partial::Infix do
4
+
5
+ context 'default min' do
6
+ let(:generator) { described_class.new }
7
+
8
+ describe 'use_exact_for_partial?' do
9
+ it 'returns false' do
10
+ described_class.new.use_exact_for_partial?.should == false
11
+ end
12
+ end
13
+ describe 'min' do
14
+ it 'should return the right value' do
15
+ generator.min.should == 1
16
+ end
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
+ lorian: [1],
24
+ flori: [1],
25
+ loria: [1],
26
+ orian: [1],
27
+ flor: [1],
28
+ lori: [1],
29
+ oria: [1],
30
+ rian: [1],
31
+ flo: [1],
32
+ lor: [1],
33
+ ori: [1],
34
+ ria: [1],
35
+ ian: [1],
36
+ fl: [1, 2],
37
+ lo: [1],
38
+ or: [1],
39
+ ri: [1],
40
+ ia: [1, 2],
41
+ an: [1],
42
+ f: [1, 2],
43
+ l: [1, 2],
44
+ o: [1],
45
+ r: [1],
46
+ i: [1, 2],
47
+ a: [1, 2],
48
+ n: [1],
49
+ flavia: [2],
50
+ flavi: [2],
51
+ lavia: [2],
52
+ flav: [2],
53
+ lavi: [2],
54
+ avia: [2],
55
+ fla: [2],
56
+ lav: [2],
57
+ avi: [2],
58
+ via: [2],
59
+ la: [2],
60
+ av: [2],
61
+ vi: [2],
62
+ v: [2]
63
+ }
64
+ end
65
+ it "should be fast" do
66
+ performance_of { generator.generate_from(florian: [1], flavia: [2]) }.should < 0.0001
67
+ end
68
+ it "should handle duplicate ids" do
69
+ generator.generate_from(flo: [1], fla: [1]).should == {
70
+ flo: [1],
71
+ fl: [1],
72
+ lo: [1],
73
+ f: [1],
74
+ l: [1],
75
+ o: [1],
76
+ a: [1],
77
+ fla: [1],
78
+ la: [1],
79
+ }
80
+ end
81
+ end
82
+ end
83
+ context 'from set' do
84
+ describe 'negative min' do
85
+ before(:each) do
86
+ @generator = described_class.new min: -2
87
+ end
88
+ it 'should generate the right index' do
89
+ @generator.generate_from(florian: [1], flavia: [2]).should == {
90
+ :florian => [1],
91
+ :floria => [1],
92
+ :lorian => [1],
93
+ :flavia => [2],
94
+ :flavi => [2],
95
+ :lavia => [2]
96
+ }
97
+ end
98
+ end
99
+ context "large min" do
100
+ before(:each) do
101
+ @generator = described_class.new min: 10
102
+ end
103
+ describe 'generate_from' do
104
+ it 'should generate the right index' do
105
+ @generator.generate_from(florian: [1], :'01234567890' => [2]).should == {
106
+ :'01234567890' => [2],
107
+ :'0123456789' => [2],
108
+ :'1234567890' => [2]
109
+ }
110
+ end
111
+ end
112
+ end
113
+ context 'default max' do
114
+ before(:each) do
115
+ @generator = described_class.new min: 4
116
+ end
117
+ describe 'max' do
118
+ it 'should return the right value' do
119
+ @generator.max.should == -1
120
+ end
121
+ end
122
+ describe 'min' do
123
+ it 'should return the right value' do
124
+ @generator.min.should == 4
125
+ end
126
+ end
127
+ describe 'generate_from' do
128
+ it 'should generate the right index' do
129
+ @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
130
+ :florian => [1],
131
+ :floria => [1],
132
+ :lorian => [1],
133
+ :flori => [1],
134
+ :loria => [1],
135
+ :orian => [1],
136
+ :flor => [1],
137
+ :lori => [1],
138
+ :oria => [1],
139
+ :rian => [1],
140
+ :flavia => [2],
141
+ :flavi => [2],
142
+ :lavia => [2],
143
+ :flav => [2],
144
+ :lavi => [2],
145
+ :avia => [2]
146
+ }
147
+ end
148
+ end
149
+ describe "a bigger example with disjunct symbols" do
150
+ before(:each) do
151
+ abc = ('A'..'Z').to_a + ('a'..'z').to_a
152
+ @index = {}
153
+ 52.times do |i|
154
+ @index[abc.join.to_sym] = [i]
155
+ character = abc.shift
156
+ abc << character
157
+ end
158
+ end
159
+ it "should be fast" do
160
+ performance_of { @generator.generate_from(@index) }.should < 0.06
161
+ end
162
+ end
163
+ describe "a bigger example with almost identical symbols" do
164
+ before(:each) do
165
+ abc = ('A'..'Z').to_a + ('a'..'z').to_a
166
+ @index = {}
167
+ 52.times do |i|
168
+ @index[(abc.join + abc[i].to_s).to_sym] = [i]
169
+ end
170
+ end
171
+ it "should be fast" do
172
+ performance_of { @generator.generate_from(@index) }.should < 0.06
173
+ end
174
+ end
175
+ end
176
+ context 'to set' do
177
+ before(:each) do
178
+ @generator = described_class.new min: 4, max: -2
179
+ end
180
+ describe 'max' do
181
+ it 'should return the right value' do
182
+ @generator.max.should == -2
183
+ end
184
+ end
185
+ describe 'min' do
186
+ it 'should return the right value' do
187
+ @generator.min.should == 4
188
+ end
189
+ end
190
+ describe 'generate_from' do
191
+ it 'should generate the right index' do
192
+ @generator.generate_from( :florian => [1], :flavia => [2] ).should == {
193
+ :floria => [1],
194
+ :lorian => [1],
195
+ :flori => [1],
196
+ :loria => [1],
197
+ :orian => [1],
198
+ :flor => [1],
199
+ :lori => [1],
200
+ :oria => [1],
201
+ :rian => [1],
202
+ :flavi => [2],
203
+ :lavia => [2],
204
+ :flav => [2],
205
+ :lavi => [2],
206
+ :avia => [2]
207
+ }
208
+ end
209
+ end
210
+ end
211
+ context 'min/max set' do
212
+ before(:each) do
213
+ @generator = described_class.new min: 4, max: 0
214
+ end
215
+ describe 'max' do
216
+ it 'should return the right value' do
217
+ @generator.max.should == 0
218
+ end
219
+ end
220
+ describe 'min' do
221
+ it 'should return the right value' do
222
+ @generator.min.should == 4
223
+ end
224
+ end
225
+ describe 'generate_from' do
226
+ it 'should generate the right index' do
227
+ @generator.generate_from( :florian => [1], :flavia => [2] ).should == {}
228
+ end
229
+ end
230
+ end
231
+ end
232
+
233
+ end
@@ -117,7 +117,7 @@ describe Picky::Indexed::Bundle do
117
117
  it "uses the right file" do
118
118
  Yajl::Parser.stub! :parse
119
119
 
120
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_inverted.json', 'r'
120
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_inverted.memory.json', 'r'
121
121
 
122
122
  @bundle.load_inverted
123
123
  end
@@ -126,7 +126,7 @@ describe Picky::Indexed::Bundle do
126
126
  it "uses the right file" do
127
127
  Yajl::Parser.stub! :parse
128
128
 
129
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_weights.json', 'r'
129
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_weights.memory.json', 'r'
130
130
 
131
131
  @bundle.load_weights
132
132
  end
@@ -135,7 +135,7 @@ describe Picky::Indexed::Bundle do
135
135
  it "uses the right file" do
136
136
  Marshal.stub! :load
137
137
 
138
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_similarity.dump', 'r:binary'
138
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_similarity.memory.dump', 'r:binary'
139
139
 
140
140
  @bundle.load_similarity
141
141
  end
@@ -144,7 +144,7 @@ describe Picky::Indexed::Bundle do
144
144
  it "uses the right file" do
145
145
  Yajl::Parser.stub! :parse
146
146
 
147
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_configuration.json', 'r'
147
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_configuration.memory.json', 'r'
148
148
 
149
149
  @bundle.load_configuration
150
150
  end
@@ -159,16 +159,16 @@ describe Picky::Indexed::Bundle do
159
159
  @bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, :similarity
160
160
  end
161
161
  it 'should initialize the index correctly' do
162
- @bundle.backend_inverted.should be_kind_of(Picky::Backends::File::JSON)
162
+ @bundle.backend_inverted.should be_kind_of(Picky::Backends::Memory::JSON)
163
163
  end
164
164
  it 'should initialize the weights index correctly' do
165
- @bundle.backend_weights.should be_kind_of(Picky::Backends::File::JSON)
165
+ @bundle.backend_weights.should be_kind_of(Picky::Backends::Memory::JSON)
166
166
  end
167
167
  it 'should initialize the similarity index correctly' do
168
- @bundle.backend_similarity.should be_kind_of(Picky::Backends::File::Marshal)
168
+ @bundle.backend_similarity.should be_kind_of(Picky::Backends::Memory::Marshal)
169
169
  end
170
170
  it 'should initialize the configuration correctly' do
171
- @bundle.backend_configuration.should be_kind_of(Picky::Backends::File::JSON)
171
+ @bundle.backend_configuration.should be_kind_of(Picky::Backends::Memory::JSON)
172
172
  end
173
173
  it 'should initialize the similarity strategy correctly' do
174
174
  @bundle.similarity_strategy.should == :similarity
@@ -5,7 +5,7 @@ describe Picky::Query::Allocation do
5
5
  before(:each) do
6
6
  @backend = stub :backend
7
7
  @index = stub :index, :result_identifier => :some_result_identifier, :backend => @backend
8
- @combinations = stub :combinations
8
+ @combinations = stub :combinations, :empty? => false
9
9
  @allocation = described_class.new @index, @combinations
10
10
  end
11
11
 
@@ -132,7 +132,7 @@ describe Picky::Query::Allocation do
132
132
  describe 'to_result' do
133
133
  context 'with few combinations' do
134
134
  before(:each) do
135
- @allocation = described_class.new @index, stub(:combinations, :to_result => [:some_result])
135
+ @allocation = described_class.new @index, stub(:combinations, :empty? => false, :to_result => [:some_result])
136
136
  @allocation.instance_variable_set :@score, :some_score
137
137
  end
138
138
  context 'with ids' do
@@ -147,7 +147,9 @@ describe Picky::Query::Allocation do
147
147
  end
148
148
  context 'with results' do
149
149
  before(:each) do
150
- combinations = stub :combinations, :to_result => [:some_result1, :some_result2]
150
+ combinations = stub :combinations,
151
+ :empty? => false,
152
+ :to_result => [:some_result1, :some_result2]
151
153
  @allocation = described_class.new @index, combinations
152
154
  @allocation.instance_variable_set :@score, :some_score
153
155
  end
@@ -163,7 +165,7 @@ describe Picky::Query::Allocation do
163
165
  end
164
166
  context 'without results' do
165
167
  before(:each) do
166
- @allocation = described_class.new @index, stub(:combinations, :to_result => [])
168
+ @allocation = described_class.new @index, stub(:combinations, :empty? => true)
167
169
  @allocation.instance_variable_set :@score, :some_score
168
170
  end
169
171
  it 'should return nil' do
@@ -178,7 +180,7 @@ describe Picky::Query::Allocation do
178
180
 
179
181
  describe 'to_json' do
180
182
  before(:each) do
181
- @allocation = described_class.new @index, stub(:combination, :to_result => [:some_result1, :some_result2])
183
+ @allocation = described_class.new @index, stub(:combination, :empty? => false, :to_result => [:some_result1, :some_result2])
182
184
  @allocation.instance_variable_set :@score, :some_score
183
185
  end
184
186
  it 'should output the correct json string' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 3.1.0
5
+ version: 3.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-08-26 00:00:00 +10:00
13
+ date: 2011-08-31 00:00:00 +02:00
14
14
  default_executable: picky
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - "="
34
34
  - !ruby/object:Gem::Version
35
- version: 3.1.0
35
+ version: 3.1.1
36
36
  type: :development
37
37
  version_requirements: *id002
38
38
  description: Fast Ruby semantic text search engine with comfortable single field interface.
@@ -54,13 +54,16 @@ files:
54
54
  - lib/picky/backends/backend.rb
55
55
  - lib/picky/backends/file/basic.rb
56
56
  - lib/picky/backends/file/json.rb
57
- - lib/picky/backends/file/marshal.rb
58
- - lib/picky/backends/file/text.rb
57
+ - lib/picky/backends/file.rb
58
+ - lib/picky/backends/memory/basic.rb
59
+ - lib/picky/backends/memory/json.rb
60
+ - lib/picky/backends/memory/marshal.rb
61
+ - lib/picky/backends/memory/text.rb
59
62
  - lib/picky/backends/memory.rb
60
63
  - lib/picky/backends/redis/basic.rb
61
- - lib/picky/backends/redis/float_hash.rb
62
- - lib/picky/backends/redis/list_hash.rb
63
- - lib/picky/backends/redis/string_hash.rb
64
+ - lib/picky/backends/redis/float.rb
65
+ - lib/picky/backends/redis/list.rb
66
+ - lib/picky/backends/redis/string.rb
64
67
  - lib/picky/backends/redis.rb
65
68
  - lib/picky/bundle.rb
66
69
  - lib/picky/bundling.rb
@@ -87,6 +90,7 @@ files:
87
90
  - lib/picky/generators/aliases.rb
88
91
  - lib/picky/generators/base.rb
89
92
  - lib/picky/generators/partial/default.rb
93
+ - lib/picky/generators/partial/infix.rb
90
94
  - lib/picky/generators/partial/none.rb
91
95
  - lib/picky/generators/partial/strategy.rb
92
96
  - lib/picky/generators/partial/substring.rb
@@ -172,16 +176,17 @@ files:
172
176
  - spec/lib/adapters/rack/query_spec.rb
173
177
  - spec/lib/analyzer_spec.rb
174
178
  - spec/lib/application_spec.rb
175
- - spec/lib/backends/file/basic_spec.rb
176
- - spec/lib/backends/file/json_spec.rb
177
- - spec/lib/backends/file/marshal_spec.rb
178
- - spec/lib/backends/file/text_spec.rb
179
+ - spec/lib/backends/memory/basic_spec.rb
180
+ - spec/lib/backends/memory/json_spec.rb
181
+ - spec/lib/backends/memory/marshal_spec.rb
182
+ - spec/lib/backends/memory/text_spec.rb
179
183
  - spec/lib/backends/memory_spec.rb
180
184
  - spec/lib/backends/redis/basic_spec.rb
181
- - spec/lib/backends/redis/float_hash_spec.rb
182
- - spec/lib/backends/redis/list_hash_spec.rb
183
- - spec/lib/backends/redis/string_hash_spec.rb
185
+ - spec/lib/backends/redis/float_spec.rb
186
+ - spec/lib/backends/redis/list_spec.rb
187
+ - spec/lib/backends/redis/string_spec.rb
184
188
  - spec/lib/backends/redis_spec.rb
189
+ - spec/lib/bundle_spec.rb
185
190
  - spec/lib/bundling_spec.rb
186
191
  - spec/lib/calculations/location_spec.rb
187
192
  - spec/lib/categories_indexed_spec.rb
@@ -199,6 +204,7 @@ files:
199
204
  - spec/lib/generators/aliases_spec.rb
200
205
  - spec/lib/generators/cacher_strategy_spec.rb
201
206
  - spec/lib/generators/partial/default_spec.rb
207
+ - spec/lib/generators/partial/infix_spec.rb
202
208
  - spec/lib/generators/partial/none_spec.rb
203
209
  - spec/lib/generators/partial/substring_spec.rb
204
210
  - spec/lib/generators/partial_generator_spec.rb
@@ -294,16 +300,17 @@ test_files:
294
300
  - spec/lib/adapters/rack/query_spec.rb
295
301
  - spec/lib/analyzer_spec.rb
296
302
  - spec/lib/application_spec.rb
297
- - spec/lib/backends/file/basic_spec.rb
298
- - spec/lib/backends/file/json_spec.rb
299
- - spec/lib/backends/file/marshal_spec.rb
300
- - spec/lib/backends/file/text_spec.rb
303
+ - spec/lib/backends/memory/basic_spec.rb
304
+ - spec/lib/backends/memory/json_spec.rb
305
+ - spec/lib/backends/memory/marshal_spec.rb
306
+ - spec/lib/backends/memory/text_spec.rb
301
307
  - spec/lib/backends/memory_spec.rb
302
308
  - spec/lib/backends/redis/basic_spec.rb
303
- - spec/lib/backends/redis/float_hash_spec.rb
304
- - spec/lib/backends/redis/list_hash_spec.rb
305
- - spec/lib/backends/redis/string_hash_spec.rb
309
+ - spec/lib/backends/redis/float_spec.rb
310
+ - spec/lib/backends/redis/list_spec.rb
311
+ - spec/lib/backends/redis/string_spec.rb
306
312
  - spec/lib/backends/redis_spec.rb
313
+ - spec/lib/bundle_spec.rb
307
314
  - spec/lib/bundling_spec.rb
308
315
  - spec/lib/calculations/location_spec.rb
309
316
  - spec/lib/categories_indexed_spec.rb
@@ -321,6 +328,7 @@ test_files:
321
328
  - spec/lib/generators/aliases_spec.rb
322
329
  - spec/lib/generators/cacher_strategy_spec.rb
323
330
  - spec/lib/generators/partial/default_spec.rb
331
+ - spec/lib/generators/partial/infix_spec.rb
324
332
  - spec/lib/generators/partial/none_spec.rb
325
333
  - spec/lib/generators/partial/substring_spec.rb
326
334
  - spec/lib/generators/partial_generator_spec.rb