picky 4.0.0pre6 → 4.0.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.
Files changed (45) hide show
  1. data/lib/picky/api/category/partial.rb +26 -0
  2. data/lib/picky/api/category/similarity.rb +26 -0
  3. data/lib/picky/api/category/weight.rb +26 -0
  4. data/lib/picky/api/search/boost.rb +28 -0
  5. data/lib/picky/api/source.rb +35 -0
  6. data/lib/picky/api/tokenizer/character_substituter.rb +22 -0
  7. data/lib/picky/api/tokenizer.rb +37 -0
  8. data/lib/picky/bundle.rb +1 -1
  9. data/lib/picky/bundle_realtime.rb +2 -2
  10. data/lib/picky/category.rb +12 -6
  11. data/lib/picky/category_indexing.rb +2 -8
  12. data/lib/picky/generators/similarity/double_metaphone.rb +1 -1
  13. data/lib/picky/generators/similarity/metaphone.rb +1 -1
  14. data/lib/picky/generators/similarity/none.rb +1 -1
  15. data/lib/picky/generators/similarity/soundex.rb +1 -1
  16. data/lib/picky/index_indexing.rb +5 -25
  17. data/lib/picky/loader.rb +15 -5
  18. data/lib/picky/query/allocation.rb +1 -1
  19. data/lib/picky/query/{weights.rb → boosts.rb} +17 -17
  20. data/lib/picky/query/combinations.rb +2 -2
  21. data/lib/picky/search.rb +17 -19
  22. data/lib/picky/tokenizer.rb +7 -4
  23. data/spec/lib/api/category/partial_spec.rb +49 -0
  24. data/spec/lib/api/category/similarity_spec.rb +50 -0
  25. data/spec/lib/api/category/weight_spec.rb +47 -0
  26. data/spec/lib/api/search/boost_spec.rb +44 -0
  27. data/spec/lib/api/source_spec.rb +68 -0
  28. data/spec/lib/api/tokenizer/character_substituter_spec.rb +34 -0
  29. data/spec/lib/api/tokenizer_spec.rb +42 -0
  30. data/spec/lib/category_indexed_spec.rb +2 -2
  31. data/spec/lib/category_indexing_spec.rb +11 -24
  32. data/spec/lib/category_spec.rb +48 -11
  33. data/spec/lib/generators/similarity/double_metaphone_spec.rb +1 -1
  34. data/spec/lib/generators/similarity/metaphone_spec.rb +1 -1
  35. data/spec/lib/generators/similarity/none_spec.rb +1 -1
  36. data/spec/lib/generators/similarity/soundex_spec.rb +1 -1
  37. data/spec/lib/index_indexing_spec.rb +10 -14
  38. data/spec/lib/index_spec.rb +1 -1
  39. data/spec/lib/query/allocation_spec.rb +2 -2
  40. data/spec/lib/query/boosts_spec.rb +79 -0
  41. data/spec/lib/query/combinations_spec.rb +3 -3
  42. data/spec/lib/search_spec.rb +13 -13
  43. data/spec/lib/tokenizer_spec.rb +12 -8
  44. metadata +44 -23
  45. data/spec/lib/query/weights_spec.rb +0 -81
@@ -26,10 +26,10 @@ describe Picky::Query::Combinations do
26
26
 
27
27
  describe "weighted_score" do
28
28
  it "uses the weights' score method" do
29
- weights = stub :weights
30
- weights.should_receive(:score_for).once.with @combinations_ary
29
+ boosts = stub :boosts
30
+ boosts.should_receive(:boost_for).once.with @combinations_ary
31
31
 
32
- @combinations.weighted_score weights
32
+ @combinations.boost_for boosts
33
33
  end
34
34
  end
35
35
 
@@ -32,7 +32,7 @@ describe Picky::Search do
32
32
  end
33
33
  end
34
34
  it 'works' do
35
- search.weights.should == Picky::Query::Weights.new([:a, :b] => 3, [:c, :d] => -1)
35
+ search.boosts.should == Picky::Query::Boosts.new([:a, :b] => 3, [:c, :d] => -1)
36
36
  end
37
37
  end
38
38
 
@@ -66,21 +66,21 @@ describe Picky::Search do
66
66
 
67
67
  end
68
68
 
69
- describe "weights handling" do
69
+ describe "boosts handling" do
70
70
  it "creates a default weight when no weights are given" do
71
71
  search = described_class.new
72
72
 
73
- search.weights.should be_kind_of(Picky::Query::Weights)
73
+ search.boosts.should be_kind_of(Picky::Query::Boosts)
74
74
  end
75
75
  it "handles :weights options when not yet wrapped" do
76
76
  search = described_class.new do boost [:a, :b] => +3 end
77
77
 
78
- search.weights.should be_kind_of(Picky::Query::Weights)
78
+ search.boosts.should be_kind_of(Picky::Query::Boosts)
79
79
  end
80
80
  it "handles :weights options when already wrapped" do
81
- search = described_class.new do boost Picky::Query::Weights.new([:a, :b] => +3) end
81
+ search = described_class.new do boost Picky::Query::Boosts.new([:a, :b] => +3) end
82
82
 
83
- search.weights.should be_kind_of(Picky::Query::Weights)
83
+ search.boosts.should be_kind_of(Picky::Query::Boosts)
84
84
  end
85
85
  end
86
86
 
@@ -134,7 +134,7 @@ describe Picky::Search do
134
134
  @search = described_class.new
135
135
  end
136
136
  it 'works correctly' do
137
- @search.to_s.should == 'Picky::Search(weights: Picky::Query::Weights({}))'
137
+ @search.to_s.should == 'Picky::Search(boosts: Picky::Query::Boosts({}))'
138
138
  end
139
139
  end
140
140
  context 'with weights' do
@@ -142,23 +142,23 @@ describe Picky::Search do
142
142
  @search = described_class.new @index do boost [:a, :b] => +3 end
143
143
  end
144
144
  it 'works correctly' do
145
- @search.to_s.should == 'Picky::Search(some_index, weights: Picky::Query::Weights({[:a, :b]=>3}))'
145
+ @search.to_s.should == 'Picky::Search(some_index, boosts: Picky::Query::Boosts({[:a, :b]=>3}))'
146
146
  end
147
147
  end
148
148
  context 'with special weights' do
149
149
  before(:each) do
150
- class RandomWeights
151
- def score_for combinations
150
+ class RandomBoosts
151
+ def boost_for combinations
152
152
  rand
153
153
  end
154
154
  def to_s
155
155
  "#{self.class}(rand)"
156
156
  end
157
157
  end
158
- @search = described_class.new @index do boost RandomWeights.new end
158
+ @search = described_class.new @index do boost RandomBoosts.new end
159
159
  end
160
160
  it 'works correctly' do
161
- @search.to_s.should == 'Picky::Search(some_index, weights: RandomWeights(rand))'
161
+ @search.to_s.should == 'Picky::Search(some_index, boosts: RandomBoosts(rand))'
162
162
  end
163
163
  end
164
164
  context 'without weights' do
@@ -166,7 +166,7 @@ describe Picky::Search do
166
166
  @search = described_class.new @index
167
167
  end
168
168
  it 'works correctly' do
169
- @search.to_s.should == 'Picky::Search(some_index, weights: Picky::Query::Weights({}))'
169
+ @search.to_s.should == 'Picky::Search(some_index, boosts: Picky::Query::Boosts({}))'
170
170
  end
171
171
  end
172
172
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Picky::Tokenizer do
6
-
6
+
7
7
  context 'with special instance' do
8
8
  let (:tokenizer) { described_class.new rejects_token_if: lambda { |token| token.to_s.length < 2 || token == :hello }, case_sensitive: true }
9
9
  it 'rejects tokens with length < 2' do
@@ -26,10 +26,10 @@ EXPECTED
26
26
  end
27
27
  end
28
28
  end
29
-
29
+
30
30
  context 'with normal instance' do
31
31
  let(:tokenizer) { described_class.new }
32
-
32
+
33
33
  describe 'to_s' do
34
34
  it 'spits out the right text' do
35
35
  tokenizer.to_s.should == <<-EXPECTED
@@ -43,7 +43,7 @@ Case sensitive? -
43
43
  EXPECTED
44
44
  end
45
45
  end
46
-
46
+
47
47
  describe 'rejects_token_if' do
48
48
  it 'rejects empty tokens by default' do
49
49
  tokenizer.reject(['a', nil, '', 'b']).should == ['a', 'b']
@@ -60,7 +60,11 @@ EXPECTED
60
60
  tokenizer.substitute_characters('abcdefghijklmnopqrstuvwxyzäöü').should == 'abcdefghijklmnopqrstuvwxyzäöü'
61
61
  end
62
62
  it 'raises if nothing with #substitute is given' do
63
- expect { tokenizer.substitutes_characters_with Object.new }.to raise_error("The substitutes_characters_with option needs a character substituter, which responds to #substitute.")
63
+ expect { tokenizer.substitutes_characters_with Object.new }.
64
+ to raise_error(<<-ERROR)
65
+ The substitutes_characters_with option needs a character substituter,
66
+ which responds to #substitute(text) and returns substituted_text."
67
+ ERROR
64
68
  end
65
69
  it "uses the substituter to replace characters" do
66
70
  tokenizer.substitutes_characters_with Picky::CharacterSubstituters::WestEuropean.new
@@ -84,7 +88,7 @@ EXPECTED
84
88
  end
85
89
  it 'should define a method normalize_with_patterns does nothing' do
86
90
  unchanging = stub :unchanging
87
-
91
+
88
92
  tokenizer.normalize_with_patterns(unchanging).should == unchanging
89
93
  end
90
94
  end
@@ -145,7 +149,7 @@ EXPECTED
145
149
  end
146
150
  it 'should define a method remove_illegals that does nothing' do
147
151
  unchanging = stub :unchanging
148
-
152
+
149
153
  tokenizer.remove_illegals unchanging
150
154
  end
151
155
  end
@@ -210,5 +214,5 @@ EXPECTED
210
214
  end
211
215
  end
212
216
  end
213
-
217
+
214
218
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0pre6
5
- prerelease: 5
4
+ version: 4.0.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Florian Hanke
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-16 00:00:00.000000000 Z
12
+ date: 2011-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70149986589980 !ruby/object:Gem::Requirement
16
+ requirement: &70136859666820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70149986589980
24
+ version_requirements: *70136859666820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: picky-client
27
- requirement: &70149986589080 !ruby/object:Gem::Requirement
27
+ requirement: &70136859665980 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 4.0.0pre6
32
+ version: 4.0.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70149986589080
35
+ version_requirements: *70136859665980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: text
38
- requirement: &70149986588600 !ruby/object:Gem::Requirement
38
+ requirement: &70136859663880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70149986588600
46
+ version_requirements: *70136859663880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: yajl-ruby
49
- requirement: &70149986588080 !ruby/object:Gem::Requirement
49
+ requirement: &70136859663340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70149986588080
57
+ version_requirements: *70136859663340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70149986587440 !ruby/object:Gem::Requirement
60
+ requirement: &70136859662720 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '3.0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70149986587440
68
+ version_requirements: *70136859662720
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: procrastinate
71
- requirement: &70149986602940 !ruby/object:Gem::Requirement
71
+ requirement: &70136859661300 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0.4'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70149986602940
79
+ version_requirements: *70136859661300
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rack_fast_escape
82
- requirement: &70149986602420 !ruby/object:Gem::Requirement
82
+ requirement: &70136859660460 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70149986602420
90
+ version_requirements: *70136859660460
91
91
  description: Fast Ruby semantic text search engine with comfortable single field interface.
92
92
  email: florian.hanke+picky@gmail.com
93
93
  executables:
@@ -99,6 +99,13 @@ files:
99
99
  - aux/picky/cli.rb
100
100
  - lib/picky/analytics.rb
101
101
  - lib/picky/analyzer.rb
102
+ - lib/picky/api/category/partial.rb
103
+ - lib/picky/api/category/similarity.rb
104
+ - lib/picky/api/category/weight.rb
105
+ - lib/picky/api/search/boost.rb
106
+ - lib/picky/api/source.rb
107
+ - lib/picky/api/tokenizer/character_substituter.rb
108
+ - lib/picky/api/tokenizer.rb
102
109
  - lib/picky/backends/backend.rb
103
110
  - lib/picky/backends/file/basic.rb
104
111
  - lib/picky/backends/file/json.rb
@@ -194,6 +201,7 @@ files:
194
201
  - lib/picky/performant.rb
195
202
  - lib/picky/query/allocation.rb
196
203
  - lib/picky/query/allocations.rb
204
+ - lib/picky/query/boosts.rb
197
205
  - lib/picky/query/combination.rb
198
206
  - lib/picky/query/combinations.rb
199
207
  - lib/picky/query/indexes.rb
@@ -201,7 +209,6 @@ files:
201
209
  - lib/picky/query/qualifier_category_mapper.rb
202
210
  - lib/picky/query/token.rb
203
211
  - lib/picky/query/tokens.rb
204
- - lib/picky/query/weights.rb
205
212
  - lib/picky/rack/harakiri.rb
206
213
  - lib/picky/results/exact_first.rb
207
214
  - lib/picky/results.rb
@@ -246,6 +253,13 @@ files:
246
253
  - spec/functional/terminate_early_spec.rb
247
254
  - spec/lib/analytics_spec.rb
248
255
  - spec/lib/analyzer_spec.rb
256
+ - spec/lib/api/category/partial_spec.rb
257
+ - spec/lib/api/category/similarity_spec.rb
258
+ - spec/lib/api/category/weight_spec.rb
259
+ - spec/lib/api/search/boost_spec.rb
260
+ - spec/lib/api/source_spec.rb
261
+ - spec/lib/api/tokenizer/character_substituter_spec.rb
262
+ - spec/lib/api/tokenizer_spec.rb
249
263
  - spec/lib/backends/backend_spec.rb
250
264
  - spec/lib/backends/file/basic_spec.rb
251
265
  - spec/lib/backends/file_spec.rb
@@ -317,6 +331,7 @@ files:
317
331
  - spec/lib/loader_spec.rb
318
332
  - spec/lib/query/allocation_spec.rb
319
333
  - spec/lib/query/allocations_spec.rb
334
+ - spec/lib/query/boosts_spec.rb
320
335
  - spec/lib/query/combination_spec.rb
321
336
  - spec/lib/query/combinations_spec.rb
322
337
  - spec/lib/query/indexes_check_spec.rb
@@ -325,7 +340,6 @@ files:
325
340
  - spec/lib/query/solr_spec.rb
326
341
  - spec/lib/query/token_spec.rb
327
342
  - spec/lib/query/tokens_spec.rb
328
- - spec/lib/query/weights_spec.rb
329
343
  - spec/lib/rack/harakiri_spec.rb
330
344
  - spec/lib/results/exact_first_spec.rb
331
345
  - spec/lib/results_spec.rb
@@ -352,9 +366,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
352
366
  required_rubygems_version: !ruby/object:Gem::Requirement
353
367
  none: false
354
368
  requirements:
355
- - - ! '>'
369
+ - - ! '>='
356
370
  - !ruby/object:Gem::Version
357
- version: 1.3.1
371
+ version: '0'
358
372
  requirements: []
359
373
  rubyforge_project: http://rubyforge.org/projects/picky
360
374
  rubygems_version: 1.8.11
@@ -382,6 +396,13 @@ test_files:
382
396
  - spec/functional/terminate_early_spec.rb
383
397
  - spec/lib/analytics_spec.rb
384
398
  - spec/lib/analyzer_spec.rb
399
+ - spec/lib/api/category/partial_spec.rb
400
+ - spec/lib/api/category/similarity_spec.rb
401
+ - spec/lib/api/category/weight_spec.rb
402
+ - spec/lib/api/search/boost_spec.rb
403
+ - spec/lib/api/source_spec.rb
404
+ - spec/lib/api/tokenizer/character_substituter_spec.rb
405
+ - spec/lib/api/tokenizer_spec.rb
385
406
  - spec/lib/backends/backend_spec.rb
386
407
  - spec/lib/backends/file/basic_spec.rb
387
408
  - spec/lib/backends/file_spec.rb
@@ -453,6 +474,7 @@ test_files:
453
474
  - spec/lib/loader_spec.rb
454
475
  - spec/lib/query/allocation_spec.rb
455
476
  - spec/lib/query/allocations_spec.rb
477
+ - spec/lib/query/boosts_spec.rb
456
478
  - spec/lib/query/combination_spec.rb
457
479
  - spec/lib/query/combinations_spec.rb
458
480
  - spec/lib/query/indexes_check_spec.rb
@@ -461,7 +483,6 @@ test_files:
461
483
  - spec/lib/query/solr_spec.rb
462
484
  - spec/lib/query/token_spec.rb
463
485
  - spec/lib/query/tokens_spec.rb
464
- - spec/lib/query/weights_spec.rb
465
486
  - spec/lib/rack/harakiri_spec.rb
466
487
  - spec/lib/results/exact_first_spec.rb
467
488
  - spec/lib/results_spec.rb
@@ -1,81 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Picky::Query::Weights do
4
-
5
- context 'with weights' do
6
- before(:each) do
7
- @weights = described_class.new [:test1, :test2] => 6,
8
- [:test1] => 5,
9
- [:test3] => 3,
10
- [:test3, :test2] => 4,
11
- [:test1, :test4] => 5,
12
- [:test4, :test1] => 5,
13
- [:test4, :test1, :test2] => 4,
14
- [:test1, :test4, :test2] => 4,
15
- [:test4, :test5] => 3,
16
- [:test5, :test1] => 2,
17
- [:test1, :test5] => 2,
18
- [:test3, :test1] => 2,
19
- [:test1, :test3] => 2
20
- end
21
-
22
- describe 'score_for' do
23
- it 'gets the category names from the combinations' do
24
- combinations = [
25
- stub(:combination1, :category_name => :test1),
26
- stub(:combination1, :category_name => :test2)
27
- ]
28
-
29
- @weights.score_for(combinations).should == +6
30
- end
31
- end
32
-
33
- describe "weight_for" do
34
- it "should return zero if there is no specific weight" do
35
- @weights.weight_for([:not_a_specific_allocation]).should be_zero
36
- end
37
- end
38
-
39
- def self.it_should_return_a_specific_weight_for(allocation, weight)
40
- it "should return weight #{weight} for #{allocation.inspect}" do
41
- @weights.weight_for(allocation).should == weight
42
- end
43
- end
44
-
45
- it_should_return_a_specific_weight_for [:test1, :test2], 6
46
- it_should_return_a_specific_weight_for [:test1], 5
47
- it_should_return_a_specific_weight_for [:test1, :test3], 2
48
- it_should_return_a_specific_weight_for [:test3], 3
49
- it_should_return_a_specific_weight_for [:test3, :test2], 4
50
- it_should_return_a_specific_weight_for [:test1, :test4], 5
51
- it_should_return_a_specific_weight_for [:test4, :test1], 5
52
- it_should_return_a_specific_weight_for [:test4, :test1, :test2], 4
53
- it_should_return_a_specific_weight_for [:test1, :test4, :test2], 4
54
- it_should_return_a_specific_weight_for [:test4, :test5], 3
55
- it_should_return_a_specific_weight_for [:test5, :test1], 2
56
- it_should_return_a_specific_weight_for [:test1, :test5], 2
57
- it_should_return_a_specific_weight_for [:test3, :test1], 2
58
-
59
- describe 'to_s' do
60
- it 'is correct' do
61
- @weights.to_s.should == "Picky::Query::Weights({[:test1, :test2]=>6, [:test1]=>5, [:test3]=>3, [:test3, :test2]=>4, [:test1, :test4]=>5, [:test4, :test1]=>5, [:test4, :test1, :test2]=>4, [:test1, :test4, :test2]=>4, [:test4, :test5]=>3, [:test5, :test1]=>2, [:test1, :test5]=>2, [:test3, :test1]=>2, [:test1, :test3]=>2})"
62
- end
63
- end
64
- describe 'empty?' do
65
- it 'is correct' do
66
- @weights.empty?.should == false
67
- end
68
- end
69
- end
70
- context 'without weights' do
71
- before(:each) do
72
- @weights = described_class.new
73
- end
74
- describe 'empty?' do
75
- it 'is correct' do
76
- @weights.empty?.should == true
77
- end
78
- end
79
- end
80
-
81
- end