picky 3.2.0 → 3.3.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 (85) hide show
  1. data/aux/picky/cli.rb +3 -1
  2. data/lib/picky/backends/backend.rb +16 -0
  3. data/lib/picky/backends/file/basic.rb +18 -9
  4. data/lib/picky/backends/file/json.rb +1 -0
  5. data/lib/picky/backends/file.rb +8 -4
  6. data/lib/picky/backends/helpers/file.rb +6 -0
  7. data/lib/picky/backends/memory/basic.rb +10 -2
  8. data/lib/picky/backends/memory/json.rb +1 -6
  9. data/lib/picky/backends/memory/marshal.rb +1 -6
  10. data/lib/picky/backends/memory/text.rb +1 -0
  11. data/lib/picky/backends/memory.rb +8 -4
  12. data/lib/picky/backends/redis/basic.rb +12 -9
  13. data/lib/picky/backends/redis.rb +10 -4
  14. data/lib/picky/bundle.rb +14 -0
  15. data/lib/picky/bundle_indexed.rb +110 -0
  16. data/lib/picky/bundle_indexing.rb +177 -0
  17. data/lib/picky/bundle_realtime.rb +80 -0
  18. data/lib/picky/categories.rb +5 -1
  19. data/lib/picky/category.rb +12 -20
  20. data/lib/picky/category_indexed.rb +3 -6
  21. data/lib/picky/category_indexing.rb +19 -18
  22. data/lib/picky/category_realtime.rb +5 -10
  23. data/lib/picky/extensions/symbol.rb +1 -1
  24. data/lib/picky/generators/partial/default.rb +1 -1
  25. data/lib/picky/generators/partial/postfix.rb +30 -0
  26. data/lib/picky/generators/partial/substring.rb +8 -2
  27. data/lib/picky/index.rb +3 -3
  28. data/lib/picky/index_indexing.rb +3 -2
  29. data/lib/picky/indexers/base.rb +0 -8
  30. data/lib/picky/indexers/parallel.rb +1 -1
  31. data/lib/picky/loader.rb +15 -15
  32. data/lib/picky/query/qualifier_category_mapper.rb +1 -1
  33. data/lib/picky/rack/harakiri.rb +3 -1
  34. data/lib/picky/sources/db.rb +11 -0
  35. data/lib/picky/statistics.rb +2 -2
  36. data/lib/picky/tokenizer.rb +1 -1
  37. data/lib/picky/tokenizers/location.rb +1 -1
  38. data/lib/picky/wrappers/bundle/calculation.rb +45 -0
  39. data/lib/picky/wrappers/bundle/delegators.rb +69 -0
  40. data/lib/picky/wrappers/bundle/exact_partial.rb +38 -0
  41. data/lib/picky/{indexed/wrappers → wrappers}/bundle/location.rb +6 -4
  42. data/lib/picky/wrappers/bundle/wrapper.rb +29 -0
  43. data/lib/picky/wrappers/category/exact_first.rb +55 -0
  44. data/lib/picky/wrappers/category/location.rb +33 -0
  45. data/lib/picky/{sources/wrappers → wrappers/sources}/base.rb +7 -3
  46. data/lib/picky/{sources/wrappers → wrappers/sources}/location.rb +3 -3
  47. data/lib/picky.rb +10 -11
  48. data/spec/aux/picky/cli_spec.rb +5 -5
  49. data/spec/lib/backends/backend_spec.rb +39 -0
  50. data/spec/lib/backends/file/basic_spec.rb +59 -0
  51. data/spec/lib/backends/file_spec.rb +105 -0
  52. data/spec/lib/backends/memory/basic_spec.rb +43 -15
  53. data/spec/lib/backends/memory_spec.rb +108 -54
  54. data/spec/lib/backends/redis/basic_spec.rb +81 -57
  55. data/spec/lib/backends/redis_spec.rb +120 -66
  56. data/spec/lib/category_indexed_spec.rb +12 -12
  57. data/spec/lib/category_indexing_spec.rb +23 -23
  58. data/spec/lib/category_spec.rb +14 -14
  59. data/spec/lib/cores_spec.rb +2 -2
  60. data/spec/lib/extensions/object_spec.rb +7 -7
  61. data/spec/lib/generators/partial/postfix_spec.rb +131 -0
  62. data/spec/lib/generators/partial/substring_spec.rb +29 -4
  63. data/spec/lib/generators/weights_generator_spec.rb +3 -3
  64. data/spec/lib/index_indexing_spec.rb +11 -15
  65. data/spec/lib/index_spec.rb +8 -8
  66. data/spec/lib/indexed/bundle_realtime_spec.rb +18 -18
  67. data/spec/lib/indexed/bundle_spec.rb +21 -21
  68. data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +9 -9
  69. data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +8 -8
  70. data/spec/lib/indexed/wrappers/exact_first_spec.rb +16 -16
  71. data/spec/lib/indexers/base_spec.rb +6 -25
  72. data/spec/lib/indexes_spec.rb +33 -22
  73. data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +2 -2
  74. data/spec/lib/indexing/bundle_spec.rb +27 -28
  75. data/spec/lib/sources/wrappers/base_spec.rb +7 -7
  76. data/spec/lib/sources/wrappers/location_spec.rb +8 -8
  77. metadata +48 -38
  78. data/lib/picky/indexed/bundle.rb +0 -125
  79. data/lib/picky/indexed/bundle_realtime.rb +0 -76
  80. data/lib/picky/indexed/wrappers/bundle/calculation.rb +0 -47
  81. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +0 -47
  82. data/lib/picky/indexed/wrappers/category/location.rb +0 -31
  83. data/lib/picky/indexed/wrappers/exact_first.rb +0 -59
  84. data/lib/picky/indexing/bundle.rb +0 -183
  85. data/lib/picky/indexing/wrappers/category/location.rb +0 -29
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Picky::Category do
4
-
4
+
5
5
  before(:each) do
6
6
  @index = Picky::Index.new :some_index
7
7
  @source = stub :some_given_source, :key_format => nil
8
8
  end
9
9
  let(:category) { described_class.new(:some_category, @index, :source => @source).tap { |c| c.stub! :timed_exclaim } }
10
-
10
+
11
11
  context "unit specs" do
12
- let(:exact) { category.indexing_exact }
13
- let(:partial) { category.indexing_partial }
14
-
12
+ let(:exact) { category.exact }
13
+ let(:partial) { category.partial }
14
+
15
15
  describe 'backup' do
16
16
  it 'delegates to both bundles' do
17
17
  exact.should_receive(:backup).once.with()
18
18
  partial.should_receive(:backup).once.with()
19
-
19
+
20
20
  category.backup
21
21
  end
22
22
  end
@@ -24,7 +24,7 @@ describe Picky::Category do
24
24
  it 'delegates to both bundles' do
25
25
  exact.should_receive(:restore).once.with()
26
26
  partial.should_receive(:restore).once.with()
27
-
27
+
28
28
  category.restore
29
29
  end
30
30
  end
@@ -32,7 +32,7 @@ describe Picky::Category do
32
32
  it 'delegates to both bundles' do
33
33
  exact.should_receive(:raise_unless_cache_exists).once.with()
34
34
  partial.should_receive(:raise_unless_cache_exists).once.with()
35
-
35
+
36
36
  category.check
37
37
  end
38
38
  end
@@ -40,12 +40,12 @@ describe Picky::Category do
40
40
  it 'delegates to both bundles' do
41
41
  exact.should_receive(:delete).once.with()
42
42
  partial.should_receive(:delete).once.with()
43
-
43
+
44
44
  category.clear
45
45
  end
46
46
  end
47
-
48
- describe 'dump_caches' do
47
+
48
+ describe 'dump' do
49
49
  before(:each) do
50
50
  exact.stub! :dump
51
51
  partial.stub! :dump
@@ -53,23 +53,23 @@ describe Picky::Category do
53
53
  it 'should dump the exact index' do
54
54
  exact.should_receive(:dump).once.with
55
55
 
56
- category.dump_caches
56
+ category.dump
57
57
  end
58
58
  it 'should dump the partial index' do
59
59
  partial.should_receive(:dump).once.with
60
60
 
61
- category.dump_caches
61
+ category.dump
62
62
  end
63
63
  end
64
-
64
+
65
65
  describe 'generate_caches_from_memory' do
66
66
  it 'should delegate to partial' do
67
67
  partial.should_receive(:generate_caches_from_memory).once.with
68
-
68
+
69
69
  category.generate_caches_from_memory
70
70
  end
71
71
  end
72
-
72
+
73
73
  describe 'generate_partial' do
74
74
  it 'should return whatever the partial generation returns' do
75
75
  exact.stub! :index
@@ -99,13 +99,13 @@ describe Picky::Category do
99
99
  category.should_receive(:generate_caches_from_source).once.with().ordered
100
100
  category.should_receive(:generate_partial).once.with().ordered
101
101
  category.should_receive(:generate_caches_from_memory).once.with().ordered
102
- category.should_receive(:dump_caches).once.with().ordered
102
+ category.should_receive(:dump).once.with().ordered
103
103
  category.should_receive(:timed_exclaim).once.ordered
104
-
104
+
105
105
  category.cache
106
106
  end
107
107
  end
108
-
108
+
109
109
  describe 'key_format' do
110
110
  context 'source has key_format' do
111
111
  before(:each) do
@@ -142,7 +142,7 @@ describe Picky::Category do
142
142
  end
143
143
  end
144
144
  end
145
-
145
+
146
146
  describe 'source' do
147
147
  context 'with explicit source' do
148
148
  let(:category) { described_class.new(:some_category, @index, :source => :category_source) }
@@ -157,7 +157,7 @@ describe Picky::Category do
157
157
  end
158
158
  end
159
159
  end
160
-
160
+
161
161
  describe "index" do
162
162
  before(:each) do
163
163
  @indexer = stub :indexer, :index => nil
@@ -165,7 +165,7 @@ describe Picky::Category do
165
165
  end
166
166
  it "tells the indexer to index" do
167
167
  @indexer.should_receive(:index).once.with [category]
168
-
168
+
169
169
  category.prepare
170
170
  end
171
171
  end
@@ -177,5 +177,5 @@ describe Picky::Category do
177
177
  end
178
178
  end
179
179
  end
180
-
180
+
181
181
  end
@@ -1,22 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Picky::Category do
4
-
4
+
5
5
  let(:index) { Picky::Index.new :some_index }
6
6
  let(:category) { described_class.new :some_category, index }
7
-
7
+
8
8
  it 'should set defaults correctly' do
9
- category.indexing_exact.weights_strategy.should == Picky::Generators::Weights::Default
10
- category.indexing_exact.partial_strategy.should be_kind_of(Picky::Generators::Partial::None)
11
- category.indexing_exact.similarity_strategy.should == Picky::Generators::Similarity::Default
12
-
13
- category.indexing_partial.weights_strategy.should be_kind_of(Picky::Generators::Weights::Logarithmic)
14
- category.indexing_partial.partial_strategy.should == Picky::Generators::Partial::Default
15
- category.indexing_partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
16
-
17
- category.indexed_exact.similarity_strategy.should == Picky::Generators::Similarity::Default
18
-
19
- category.indexed_partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
9
+ category.exact.weights_strategy.should == Picky::Generators::Weights::Default
10
+ category.exact.partial_strategy.should be_kind_of(Picky::Generators::Partial::None)
11
+ category.exact.similarity_strategy.should == Picky::Generators::Similarity::Default
12
+
13
+ category.partial.weights_strategy.should be_kind_of(Picky::Generators::Weights::Logarithmic)
14
+ category.partial.partial_strategy.should == Picky::Generators::Partial::Default
15
+ category.partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
16
+
17
+ category.exact.similarity_strategy.should == Picky::Generators::Similarity::Default
18
+
19
+ category.partial.similarity_strategy.should be_kind_of(Picky::Generators::Similarity::None)
20
20
  end
21
-
21
+
22
22
  end
@@ -125,8 +125,8 @@ describe Picky::Cores do
125
125
 
126
126
  describe 'number_of_cores' do
127
127
  before(:each) do
128
- @linux = mock :linux, :null_object => true
129
- @darwin = mock :darwin, :null_object => true
128
+ @linux = mock(:linux).as_null_object
129
+ @darwin = mock(:darwin).as_null_object
130
130
  described_class.stub! :os_to_core_mapping => {
131
131
  'linux' => @linux,
132
132
  'darwin' => @darwin
@@ -33,26 +33,26 @@ describe Object do
33
33
 
34
34
  describe 'indented_to_s' do
35
35
  describe String do
36
- let(:object) { described_class.new("Hello\nTest") }
36
+ let(:string) { String.new("Hello\nTest") }
37
37
 
38
38
  it 'indents a default amount' do
39
- object.indented_to_s.should == " Hello\n Test"
39
+ string.indented_to_s.should == " Hello\n Test"
40
40
  end
41
41
  it 'indents twice' do
42
- object.indented_to_s.indented_to_s.should == " Hello\n Test"
42
+ string.indented_to_s.indented_to_s.should == " Hello\n Test"
43
43
  end
44
44
  it 'indents correctly' do
45
- object.indented_to_s(3).should == " Hello\n Test"
45
+ string.indented_to_s(3).should == " Hello\n Test"
46
46
  end
47
47
  end
48
48
  describe Array do
49
- let(:object) { described_class.new(["Hello", "Test"]) }
49
+ let(:array) { Array.new(["Hello", "Test"]) }
50
50
 
51
51
  it 'indents a default amount' do
52
- object.indented_to_s.should == " Hello\n Test"
52
+ array.indented_to_s.should == " Hello\n Test"
53
53
  end
54
54
  it 'indents twice' do
55
- object.indented_to_s.indented_to_s.should == " Hello\n Test"
55
+ array.indented_to_s.indented_to_s.should == " Hello\n Test"
56
56
  end
57
57
  end
58
58
  end
@@ -0,0 +1,131 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Generators::Partial::Postfix do
4
+
5
+ context 'default from' 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 'from' do
14
+ it 'should return the right value' do
15
+ generator.from.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
+ 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 '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
129
+ end
130
+
131
+ end
@@ -1,10 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Picky::Generators::Partial::Substring do
4
-
4
+
5
5
  context 'default from' do
6
6
  let(:generator) { described_class.new }
7
-
7
+
8
8
  describe 'use_exact_for_partial?' do
9
9
  it 'returns false' do
10
10
  described_class.new.use_exact_for_partial?.should == false
@@ -24,7 +24,7 @@ describe Picky::Generators::Partial::Substring do
24
24
  flor: [1],
25
25
  flo: [1],
26
26
  fl: [1, 2],
27
- f: [1, 2],
27
+ f: [1, 2],
28
28
  flavia: [2],
29
29
  flavi: [2],
30
30
  flav: [2],
@@ -180,6 +180,31 @@ describe Picky::Generators::Partial::Substring do
180
180
  end
181
181
  end
182
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
183
208
  end
184
-
209
+
185
210
  end
@@ -12,9 +12,9 @@ describe Picky::Generators::WeightsGenerator do
12
12
 
13
13
  result = generator.generate
14
14
 
15
- result[:c].should be_close 2.3, 0.011
16
- result[:d].should be_close 4.6, 0.011
17
- result[:e].should be_close 6.9, 0.011
15
+ result[:c].should be_within(0.011).of(2.3)
16
+ result[:d].should be_within(0.011).of(4.6)
17
+ result[:e].should be_within(0.011).of(6.9)
18
18
  end
19
19
  end
20
20
 
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Picky::Index do
4
-
4
+
5
5
  describe 'tokenizer' do
6
6
  context 'with tokenizer' do
7
7
  let(:tokenizer) { stub :tokenizer, :tokenize => '' }
@@ -29,7 +29,7 @@ describe Picky::Index do
29
29
  end
30
30
  end
31
31
  end
32
-
32
+
33
33
  context 'after_indexing' do
34
34
  context 'with it set' do
35
35
  let(:index) do
@@ -51,7 +51,7 @@ describe Picky::Index do
51
51
  end
52
52
  end
53
53
  end
54
-
54
+
55
55
  context 'in general' do
56
56
  context 'with #each source' do
57
57
  let(:index) do
@@ -77,24 +77,20 @@ describe Picky::Index do
77
77
  end
78
78
 
79
79
  it 'does things in order' do
80
- category = stub :category
81
- index.stub! :categories => [
82
- category,
83
- category,
84
- category
85
- ]
80
+ categories = stub :categories
81
+ index.stub! :categories => categories
86
82
 
87
- category.should_receive(:index).exactly(3).times
83
+ categories.should_receive(:index).once
88
84
 
89
85
  index.index
90
86
  end
91
87
  end
92
88
  end
93
-
89
+
94
90
  context "with categories" do
95
91
  before(:each) do
96
92
  the_source = []
97
-
93
+
98
94
  @index = described_class.new :some_name do
99
95
  source the_source
100
96
  end
@@ -109,7 +105,7 @@ describe Picky::Index do
109
105
  describe 'define_source' do
110
106
  it 'can be set with this method' do
111
107
  source = stub :source, :each => [].each
112
-
108
+
113
109
  @index.define_source source
114
110
 
115
111
  @index.source.should == source
@@ -138,7 +134,7 @@ describe Picky::Index do
138
134
  end
139
135
  end
140
136
  end
141
-
137
+
142
138
  context "no categories" do
143
139
  it "works" do
144
140
  described_class.new :some_name do
@@ -146,5 +142,5 @@ describe Picky::Index do
146
142
  end
147
143
  end
148
144
  end
149
-
145
+
150
146
  end
@@ -3,9 +3,9 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Picky::Index do
6
-
6
+
7
7
  let(:some_source) { stub :source, :harvest => nil, :inspect => 'some_source' }
8
-
8
+
9
9
  context 'initializer' do
10
10
  it 'works' do
11
11
  the_source = some_source
@@ -22,16 +22,16 @@ describe Picky::Index do
22
22
  end
23
23
  it 'registers with the indexes' do
24
24
  @api = described_class.allocate
25
-
25
+
26
26
  Picky::Indexes.should_receive(:register).once.with @api
27
-
27
+
28
28
  the_source = some_source
29
29
  @api.send :initialize, :some_index_name do
30
30
  source the_source
31
31
  end
32
32
  end
33
33
  end
34
-
34
+
35
35
  context 'unit' do
36
36
  let(:api) do
37
37
  the_source = some_source
@@ -39,12 +39,12 @@ describe Picky::Index do
39
39
  source the_source
40
40
  end
41
41
  end
42
-
42
+
43
43
  describe 'geo_categories' do
44
44
  it 'delegates correctly' do
45
45
  api.should_receive(:ranged_category).once.with :some_lat, 0.00898312, from: :some_lat_from
46
46
  api.should_receive(:ranged_category).once.with :some_lng, 0.01796624, from: :some_lng_from
47
-
47
+
48
48
  api.geo_categories :some_lat, :some_lng, 1, :lat_from => :some_lat_from, :lng_from => :some_lng_from
49
49
  end
50
50
  end
@@ -82,5 +82,5 @@ describe Picky::Index do
82
82
  end
83
83
  end
84
84
  end
85
-
85
+
86
86
  end
@@ -1,17 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Indexed::Bundle do
3
+ describe Picky::Bundle do
4
4
 
5
5
  before(:each) do
6
6
  @index = Picky::Index.new :some_index
7
7
  @category = Picky::Category.new :some_category, @index
8
-
8
+
9
9
  @weights = Picky::Generators::Weights::Default
10
10
  @partial = Picky::Generators::Partial::Default
11
11
  @similarity = Picky::Generators::Similarity::DoubleMetaphone.new 3
12
12
  @bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @weights, @partial, @similarity
13
13
  end
14
-
14
+
15
15
  it 'is by default empty' do
16
16
  @bundle.realtime_mapping.should == {}
17
17
  end
@@ -24,12 +24,12 @@ describe Picky::Indexed::Bundle do
24
24
  it 'is by default empty' do
25
25
  @bundle.similarity.should == {}
26
26
  end
27
-
27
+
28
28
  describe 'combined' do
29
29
  it 'works correctly' do
30
30
  @bundle.add 1, :title
31
31
  @bundle.add 2, :title
32
-
32
+
33
33
  @bundle.realtime_mapping.should == { 1 => [:title], 2 => [:title] }
34
34
  @bundle.inverted.should == { :title => [2,1] }
35
35
  @bundle.weights.should == { :title => 0.6931471805599453 }
@@ -40,7 +40,7 @@ describe Picky::Indexed::Bundle do
40
40
  @bundle.add 2, :title
41
41
  @bundle.remove 1
42
42
  @bundle.remove 2
43
-
43
+
44
44
  @bundle.realtime_mapping.should == {}
45
45
  @bundle.weights.should == {}
46
46
  @bundle.inverted.should == {}
@@ -51,7 +51,7 @@ describe Picky::Indexed::Bundle do
51
51
  @bundle.add 1, :other
52
52
  @bundle.add 1, :whatever
53
53
  @bundle.remove 1
54
-
54
+
55
55
  @bundle.realtime_mapping.should == {}
56
56
  @bundle.weights.should == {}
57
57
  @bundle.inverted.should == {}
@@ -62,7 +62,7 @@ describe Picky::Indexed::Bundle do
62
62
  @bundle.add 2, :thing
63
63
  @bundle.add 1, :other
64
64
  @bundle.remove 1
65
-
65
+
66
66
  @bundle.realtime_mapping.should == { 2 => [:thing] }
67
67
  @bundle.weights.should == { :thing => 0.0 }
68
68
  @bundle.inverted.should == { :thing => [2] }
@@ -71,7 +71,7 @@ describe Picky::Indexed::Bundle do
71
71
  it 'works correctly' do
72
72
  @bundle.add 1, :title
73
73
  @bundle.add 1, :title
74
-
74
+
75
75
  @bundle.realtime_mapping.should == { 1 => [:title] }
76
76
  @bundle.weights.should == { :title => 0.0 }
77
77
  @bundle.inverted.should == { :title => [1] }
@@ -81,35 +81,35 @@ describe Picky::Indexed::Bundle do
81
81
  @bundle.add 1, :title
82
82
  @bundle.remove 1
83
83
  @bundle.remove 1
84
-
84
+
85
85
  @bundle.realtime_mapping.should == {}
86
86
  @bundle.weights.should == {}
87
87
  @bundle.inverted.should == {}
88
88
  @bundle.similarity.should == {}
89
89
  end
90
90
  end
91
-
91
+
92
92
  describe 'add' do
93
93
  it 'works correctly' do
94
94
  @bundle.add 1, :title
95
-
95
+
96
96
  @bundle.realtime_mapping.should == { 1 => [:title] }
97
-
97
+
98
98
  @bundle.add 2, :other
99
-
99
+
100
100
  @bundle.realtime_mapping.should == { 1 => [:title], 2 => [:other] }
101
-
101
+
102
102
  @bundle.add 1, :thing
103
-
103
+
104
104
  @bundle.realtime_mapping.should == { 1 => [:title, :thing], 2 => [:other] }
105
105
  end
106
106
  it 'works correctly' do
107
107
  @bundle.add 1, :title
108
-
108
+
109
109
  @bundle.weights.should == { :title => 0.0 }
110
110
  @bundle.inverted.should == { :title => [1] }
111
111
  @bundle.similarity.should == { :TTL => [:title] }
112
112
  end
113
113
  end
114
-
114
+
115
115
  end