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
@@ -2,75 +2,129 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Backends::Memory do
4
4
 
5
- before(:each) do
6
- @backend = described_class.new
5
+ context 'with options' do
6
+ before(:each) do
7
+ @backend = described_class.new inverted: Picky::Backends::Memory::Marshal.new(:unimportant),
8
+ weights: Picky::Backends::Memory::Marshal.new(:unimportant),
9
+ similarity: Picky::Backends::Memory::JSON.new(:unimportant),
10
+ configuration: Picky::Backends::Memory::Marshal.new(:unimportant)
7
11
 
8
- @backend.stub! :timed_exclaim
9
- end
12
+ @backend.stub! :timed_exclaim
13
+ end
10
14
 
11
- describe 'create_...' do
12
- [
13
- [:inverted, Picky::Backends::Memory::JSON],
14
- [:weights, Picky::Backends::Memory::JSON],
15
- [:similarity, Picky::Backends::Memory::Marshal],
16
- [:configuration, Picky::Backends::Memory::JSON]
17
- ].each do |type, kind|
18
- it "creates and returns a(n) #{type} index" do
19
- @backend.send(:"create_#{type}",
20
- stub(type, :index_path => "spec/test_directory/index/test/some_index/some_category_some_bundle_#{type}")
21
- ).should be_kind_of(kind)
15
+ describe 'create_...' do
16
+ [
17
+ [:inverted, Picky::Backends::Memory::Marshal],
18
+ [:weights, Picky::Backends::Memory::Marshal],
19
+ [:similarity, Picky::Backends::Memory::JSON],
20
+ [:configuration, Picky::Backends::Memory::Marshal]
21
+ ].each do |type, kind|
22
+ it "creates and returns a(n) #{type} index" do
23
+ @backend.send(:"create_#{type}",
24
+ stub(type, :index_path => "spec/test_directory/index/test/some_index/some_category_some_bundle_#{type}")
25
+ ).should be_kind_of(kind)
26
+ end
22
27
  end
23
28
  end
24
29
  end
25
30
 
26
- describe "ids" do
31
+ context 'with lambda options' do
27
32
  before(:each) do
28
- @combination1 = stub :combination1
29
- @combination2 = stub :combination2
30
- @combination3 = stub :combination3
31
- @combinations = [@combination1, @combination2, @combination3]
32
- end
33
- it "should intersect correctly" do
34
- @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
35
- @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
36
- @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
33
+ @backend = described_class.new inverted: ->(bundle){ Picky::Backends::Memory::Marshal.new(bundle.index_path(:inverted)) },
34
+ weights: ->(bundle){ Picky::Backends::Memory::Marshal.new(bundle.index_path(:weights)) },
35
+ similarity: ->(bundle){ Picky::Backends::Memory::JSON.new(bundle.index_path(:similarity)) },
36
+ configuration: ->(bundle){ Picky::Backends::Memory::Marshal.new(bundle.index_path(:configuration)) }
37
37
 
38
- @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
38
+ @backend.stub! :timed_exclaim
39
39
  end
40
- it "should intersect symbol_keys correctly" do
41
- @combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
42
- @combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
43
- @combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
44
-
45
- @backend.ids(@combinations, :any, :thing).should == (:'00001'..:'0010').to_a
40
+
41
+ describe 'create_...' do
42
+ [
43
+ [:inverted, Picky::Backends::Memory::Marshal],
44
+ [:weights, Picky::Backends::Memory::Marshal],
45
+ [:similarity, Picky::Backends::Memory::JSON],
46
+ [:configuration, Picky::Backends::Memory::Marshal]
47
+ ].each do |type, kind|
48
+ it "creates and returns a(n) #{type} index" do
49
+ to_a_able_stub = Object.new
50
+ to_a_able_stub.stub! :index_path => "spec/test_directory/index/test/some_index/some_category_some_bundle_#{type}"
51
+ @backend.send(:"create_#{type}", to_a_able_stub).should be_kind_of(kind)
52
+ end
53
+ end
46
54
  end
47
- it "should intersect correctly when intermediate intersect result is empty" do
48
- @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
49
- @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
50
- @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
55
+ end
51
56
 
52
- @backend.ids(@combinations, :any, :thing).should == []
53
- end
54
- it "should be fast" do
55
- @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
56
- @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
57
- @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
57
+ context 'without options' do
58
+ before(:each) do
59
+ @backend = described_class.new
58
60
 
59
- performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
61
+ @backend.stub! :timed_exclaim
60
62
  end
61
- it "should be fast" do
62
- @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
63
- @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
64
- @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
65
-
66
- performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.00015
63
+
64
+ describe 'create_...' do
65
+ [
66
+ [:inverted, Picky::Backends::Memory::JSON],
67
+ [:weights, Picky::Backends::Memory::JSON],
68
+ [:similarity, Picky::Backends::Memory::Marshal],
69
+ [:configuration, Picky::Backends::Memory::JSON]
70
+ ].each do |type, kind|
71
+ it "creates and returns a(n) #{type} index" do
72
+ @backend.send(:"create_#{type}",
73
+ stub(type, :index_path => "spec/test_directory/index/test/some_index/some_category_some_bundle_#{type}")
74
+ ).should be_kind_of(kind)
75
+ end
76
+ end
67
77
  end
68
- it "should be fast" do
69
- @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
70
- @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
71
- @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
78
+
79
+ describe "ids" do
80
+ before(:each) do
81
+ @combination1 = stub :combination1
82
+ @combination2 = stub :combination2
83
+ @combination3 = stub :combination3
84
+ @combinations = [@combination1, @combination2, @combination3]
85
+ end
86
+ it "should intersect correctly" do
87
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
88
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
89
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
90
+
91
+ @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
92
+ end
93
+ it "should intersect symbol_keys correctly" do
94
+ @combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
95
+ @combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
96
+ @combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
72
97
 
73
- performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
98
+ @backend.ids(@combinations, :any, :thing).should == (:'00001'..:'0010').to_a
99
+ end
100
+ it "should intersect correctly when intermediate intersect result is empty" do
101
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
102
+ @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
103
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
104
+
105
+ @backend.ids(@combinations, :any, :thing).should == []
106
+ end
107
+ it "should be fast" do
108
+ @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
109
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
110
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
111
+
112
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
113
+ end
114
+ it "should be fast" do
115
+ @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
116
+ @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
117
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
118
+
119
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.00015
120
+ end
121
+ it "should be fast" do
122
+ @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
123
+ @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
124
+ @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
125
+
126
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
127
+ end
74
128
  end
75
129
  end
76
130
 
@@ -3,80 +3,104 @@ require 'spec_helper'
3
3
  describe Picky::Backends::Redis::Basic do
4
4
 
5
5
  let(:client) { stub :client }
6
- let(:index) { described_class.new client, :some_namespace }
7
-
8
- describe 'load, retrieve, backup, delete' do
9
- it 'is nothing they do (at least on the backend)' do
10
- index.should_receive(:client).never
11
-
12
- index.load
13
- index.retrieve
14
- index.backup
15
- index.delete
16
- end
17
- end
18
-
19
- describe 'empty' do
20
- it 'returns the container that is used for indexing' do
21
- index.empty.should == {}
22
- end
23
- end
24
6
 
25
- describe 'initial' do
26
- it 'is correct' do
27
- index.initial.class.should == described_class
7
+ context 'without options' do
8
+ let(:index) { described_class.new client, :some_namespace }
9
+
10
+ describe 'load, retrieve, backup, delete' do
11
+ it 'is nothing they do (at least on the backend)' do
12
+ index.should_receive(:client).never
13
+
14
+ index.load
15
+ index.retrieve
16
+ index.backup
17
+ index.delete
18
+ end
28
19
  end
29
- end
30
-
31
- describe 'cache_small?' do
32
- context 'size 0' do
33
- before(:each) do
34
- index.stub! :size => 0
20
+
21
+ describe 'empty' do
22
+ it 'returns the container that is used for indexing' do
23
+ index.empty.should == {}
35
24
  end
36
- it 'is small' do
37
- index.cache_small?.should == true
25
+ end
26
+
27
+ describe 'initial' do
28
+ it 'is correct' do
29
+ index.initial.class.should == described_class
38
30
  end
39
31
  end
40
- context 'size 1' do
41
- before(:each) do
42
- index.stub! :size => 1
32
+
33
+ describe 'cache_small?' do
34
+ context 'size 0' do
35
+ before(:each) do
36
+ index.stub! :size => 0
37
+ end
38
+ it 'is small' do
39
+ index.cache_small?.should == true
40
+ end
43
41
  end
44
- it 'is not small' do
45
- index.cache_small?.should == false
42
+ context 'size 1' do
43
+ before(:each) do
44
+ index.stub! :size => 1
45
+ end
46
+ it 'is not small' do
47
+ index.cache_small?.should == false
48
+ end
46
49
  end
47
50
  end
48
- end
49
-
50
- describe 'cache_ok?' do
51
- context 'size 0' do
52
- before(:each) do
53
- index.stub! :size => 0
51
+
52
+ describe 'cache_ok?' do
53
+ context 'size 0' do
54
+ before(:each) do
55
+ index.stub! :size => 0
56
+ end
57
+ it 'is not ok' do
58
+ index.cache_ok?.should == false
59
+ end
54
60
  end
55
- it 'is not ok' do
56
- index.cache_ok?.should == false
61
+ context 'size 1' do
62
+ before(:each) do
63
+ index.stub! :size => 1
64
+ end
65
+ it 'is ok' do
66
+ index.cache_ok?.should == true
67
+ end
57
68
  end
58
69
  end
59
- context 'size 1' do
60
- before(:each) do
61
- index.stub! :size => 1
70
+
71
+ describe "size" do
72
+ it 'delegates to the backend' do
73
+ client.should_receive(:dbsize).once.with
74
+
75
+ index.size
62
76
  end
63
- it 'is ok' do
64
- index.cache_ok?.should == true
77
+ end
78
+
79
+ describe 'to_s' do
80
+ it 'returns the cache path with the default file extension' do
81
+ index.to_s.should == 'Picky::Backends::Redis::Basic(some_namespace:*)'
65
82
  end
66
83
  end
67
84
  end
68
85
 
69
- describe "size" do
70
- it 'delegates to the backend' do
71
- client.should_receive(:dbsize).once.with
72
-
73
- index.size
86
+ context 'with options' do
87
+ let(:index) do
88
+ described_class.new client,
89
+ :some_namespace,
90
+ empty: [],
91
+ initial: []
74
92
  end
75
- end
76
-
77
- describe 'to_s' do
78
- it 'returns the cache path with the default file extension' do
79
- index.to_s.should == 'Picky::Backends::Redis::Basic(some_namespace:*)'
93
+
94
+ describe 'empty' do
95
+ it 'returns the container that is used for indexing' do
96
+ index.empty.should == []
97
+ end
98
+ end
99
+
100
+ describe 'initial' do
101
+ it 'is correct' do
102
+ index.initial.class.should == Array
103
+ end
80
104
  end
81
105
  end
82
106
 
@@ -2,78 +2,132 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Backends::Redis do
4
4
 
5
- before(:each) do
6
- @backend = described_class.new
5
+ context 'with options' do
6
+ before(:each) do
7
+ @backend = described_class.new inverted: Picky::Backends::Redis::Float.new(:unimportant, :unimportant),
8
+ weights: Picky::Backends::Redis::String.new(:unimportant, :unimportant),
9
+ similarity: Picky::Backends::Redis::Float.new(:unimportant, :unimportant),
10
+ configuration: Picky::Backends::Redis::List.new(:unimportant, :unimportant)
7
11
 
8
- @backend.stub! :timed_exclaim
12
+ @backend.stub! :timed_exclaim
13
+ end
14
+
15
+ describe 'create_...' do
16
+ [
17
+ [:inverted, Picky::Backends::Redis::Float],
18
+ [:weights, Picky::Backends::Redis::String],
19
+ [:similarity, Picky::Backends::Redis::Float],
20
+ [:configuration, Picky::Backends::Redis::List]
21
+ ].each do |type, kind|
22
+ it "creates and returns a(n) #{type} index" do
23
+ @backend.send(:"create_#{type}",
24
+ stub(type, :identifier => "some_identifier:#{type}")
25
+ ).should be_kind_of(kind)
26
+ end
27
+ end
28
+ end
9
29
  end
10
30
 
11
- describe 'create_...' do
12
- [
13
- [:inverted, Picky::Backends::Redis::List],
14
- [:weights, Picky::Backends::Redis::Float],
15
- [:similarity, Picky::Backends::Redis::List],
16
- [:configuration, Picky::Backends::Redis::String]
17
- ].each do |type, kind|
18
- it "creates and returns a(n) #{type} index" do
19
- @backend.send(:"create_#{type}",
20
- stub(type, :identifier => "some_identifier:#{type}")
21
- ).should be_kind_of(kind)
31
+ context 'with lambda options' do
32
+ before(:each) do
33
+ @backend = described_class.new inverted: ->(client, bundle){ Picky::Backends::Redis::Float.new(client, bundle.identifier(:inverted)) },
34
+ weights: ->(client, bundle){ Picky::Backends::Redis::String.new(client, bundle.identifier(:weights)) },
35
+ similarity: ->(client, bundle){ Picky::Backends::Redis::Float.new(client, bundle.identifier(:similarity)) },
36
+ configuration: ->(client, bundle){ Picky::Backends::Redis::List.new(client, bundle.identifier(:configuration)) }
37
+
38
+ @backend.stub! :timed_exclaim
39
+ end
40
+
41
+ describe 'create_...' do
42
+ [
43
+ [:inverted, Picky::Backends::Redis::Float],
44
+ [:weights, Picky::Backends::Redis::String],
45
+ [:similarity, Picky::Backends::Redis::Float],
46
+ [:configuration, Picky::Backends::Redis::List]
47
+ ].each do |type, kind|
48
+ it "creates and returns a(n) #{type} index" do
49
+ to_a_able_stub = Object.new
50
+ to_a_able_stub.stub! :identifier => "some_identifier:#{type}"
51
+ @backend.send(:"create_#{type}", to_a_able_stub).should be_kind_of(kind)
52
+ end
22
53
  end
23
54
  end
24
55
  end
25
56
 
26
- # TODO
27
- #
28
- # describe "ids" do
29
- # before(:each) do
30
- # @combination1 = stub :combination1
31
- # @combination2 = stub :combination2
32
- # @combination3 = stub :combination3
33
- # @combinations = [@combination1, @combination2, @combination3]
34
- # end
35
- # it "should intersect correctly" do
36
- # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
37
- # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
38
- # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
39
- #
40
- # @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
41
- # end
42
- # it "should intersect symbol_keys correctly" do
43
- # @combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
44
- # @combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
45
- # @combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
46
- #
47
- # @backend.ids(@combinations, :any, :thing).should == (:'00001'..:'0010').to_a
48
- # end
49
- # it "should intersect correctly when intermediate intersect result is empty" do
50
- # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
51
- # @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
52
- # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
53
- #
54
- # @backend.ids(@combinations, :any, :thing).should == []
55
- # end
56
- # it "should be fast" do
57
- # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
58
- # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
59
- # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
60
- #
61
- # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
62
- # end
63
- # it "should be fast" do
64
- # @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
65
- # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
66
- # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
67
- #
68
- # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.00015
69
- # end
70
- # it "should be fast" do
71
- # @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
72
- # @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
73
- # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
74
- #
75
- # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
76
- # end
77
- # end
57
+ context 'without options' do
58
+ before(:each) do
59
+ @backend = described_class.new
60
+
61
+ @backend.stub! :timed_exclaim
62
+ end
63
+
64
+ describe 'create_...' do
65
+ [
66
+ [:inverted, Picky::Backends::Redis::List],
67
+ [:weights, Picky::Backends::Redis::Float],
68
+ [:similarity, Picky::Backends::Redis::List],
69
+ [:configuration, Picky::Backends::Redis::String]
70
+ ].each do |type, kind|
71
+ it "creates and returns a(n) #{type} index" do
72
+ @backend.send(:"create_#{type}",
73
+ stub(type, :identifier => "some_identifier:#{type}")
74
+ ).should be_kind_of(kind)
75
+ end
76
+ end
77
+ end
78
+
79
+ # TODO
80
+ #
81
+ # describe "ids" do
82
+ # before(:each) do
83
+ # @combination1 = stub :combination1
84
+ # @combination2 = stub :combination2
85
+ # @combination3 = stub :combination3
86
+ # @combinations = [@combination1, @combination2, @combination3]
87
+ # end
88
+ # it "should intersect correctly" do
89
+ # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
90
+ # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
91
+ # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
92
+ #
93
+ # @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
94
+ # end
95
+ # it "should intersect symbol_keys correctly" do
96
+ # @combination1.should_receive(:ids).once.with.and_return (:'00001'..:'10000').to_a
97
+ # @combination2.should_receive(:ids).once.with.and_return (:'00001'..:'00100').to_a
98
+ # @combination3.should_receive(:ids).once.with.and_return (:'00001'..:'00010').to_a
99
+ #
100
+ # @backend.ids(@combinations, :any, :thing).should == (:'00001'..:'0010').to_a
101
+ # end
102
+ # it "should intersect correctly when intermediate intersect result is empty" do
103
+ # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
104
+ # @combination2.should_receive(:ids).once.with.and_return (11..100).to_a
105
+ # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
106
+ #
107
+ # @backend.ids(@combinations, :any, :thing).should == []
108
+ # end
109
+ # it "should be fast" do
110
+ # @combination1.should_receive(:ids).once.with.and_return (1..100_000).to_a
111
+ # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
112
+ # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
113
+ #
114
+ # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
115
+ # end
116
+ # it "should be fast" do
117
+ # @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
118
+ # @combination2.should_receive(:ids).once.with.and_return (1..100).to_a
119
+ # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
120
+ #
121
+ # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.00015
122
+ # end
123
+ # it "should be fast" do
124
+ # @combination1.should_receive(:ids).once.with.and_return (1..1000).to_a
125
+ # @combination2.should_receive(:ids).once.with.and_return (901..1000).to_a
126
+ # @combination3.should_receive(:ids).once.with.and_return (1..10).to_a
127
+ #
128
+ # performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
129
+ # end
130
+ # end
131
+ end
78
132
 
79
133
  end
@@ -9,18 +9,18 @@ describe Picky::Category do
9
9
  @partial_strategy = stub :partial, :use_exact_for_partial? => false
10
10
  @weights_strategy = stub :weights
11
11
  @similarity_strategy = stub :similarity
12
-
12
+
13
13
  @exact = stub :exact, :dump => nil
14
14
  @partial = stub :partial, :dump => nil
15
-
15
+
16
16
  @category = described_class.new :some_name, @index, :partial => @partial_strategy,
17
17
  :weights => @weights_strategy,
18
18
  :similarity => @similarity_strategy,
19
19
  :qualifiers => [:q, :qualifier]
20
-
20
+
21
21
  @category.stub! :exclaim
22
22
  end
23
-
23
+
24
24
  describe 'partial' do
25
25
  context 'default' do
26
26
  before(:each) do
@@ -31,12 +31,12 @@ describe Picky::Category do
31
31
  @partial_strategy.stub! :use_exact_for_partial? => true
32
32
  end
33
33
  it 'returns the partial index' do
34
- @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle)
34
+ @category.partial.should be_kind_of(Picky::Bundle)
35
35
  end
36
36
  end
37
37
  context 'with a partial strategy that uses the partial index (default)' do
38
38
  it 'returns the partial index' do
39
- @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle)
39
+ @category.partial.should be_kind_of(Picky::Bundle)
40
40
  end
41
41
  end
42
42
  end
@@ -52,17 +52,17 @@ describe Picky::Category do
52
52
  @partial_strategy.stub! :use_exact_for_partial? => true
53
53
  end
54
54
  it 'returns the partial index' do
55
- @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle)
55
+ @category.partial.should be_kind_of(Picky::Bundle)
56
56
  end
57
57
  end
58
58
  context 'with a partial strategy that uses the partial index (default)' do
59
59
  it 'returns the partial index' do
60
- @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle)
60
+ @category.partial.should be_kind_of(Picky::Bundle)
61
61
  end
62
62
  end
63
63
  end
64
64
  end
65
-
65
+
66
66
  describe 'weight' do
67
67
  before(:each) do
68
68
  @token = stub :token, :text => :some_text
@@ -139,11 +139,11 @@ describe Picky::Category do
139
139
  end
140
140
  end
141
141
  end
142
-
142
+
143
143
  context 'stubbed exact/partial' do
144
144
  before(:each) do
145
- @category.stub! :indexed_exact => (@exact = stub :exact)
146
- @category.stub! :indexed_partial => (@partial = stub :partial)
145
+ @category.stub! :exact => (@exact = stub :exact)
146
+ @category.stub! :partial => (@partial = stub :partial)
147
147
  end
148
148
  describe 'bundle_for' do
149
149
  it 'should return the right bundle' do