picky 3.2.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/aux/picky/cli.rb +3 -1
- data/lib/picky/backends/backend.rb +16 -0
- data/lib/picky/backends/file/basic.rb +18 -9
- data/lib/picky/backends/file/json.rb +1 -0
- data/lib/picky/backends/file.rb +8 -4
- data/lib/picky/backends/helpers/file.rb +6 -0
- data/lib/picky/backends/memory/basic.rb +10 -2
- data/lib/picky/backends/memory/json.rb +1 -6
- data/lib/picky/backends/memory/marshal.rb +1 -6
- data/lib/picky/backends/memory/text.rb +1 -0
- data/lib/picky/backends/memory.rb +8 -4
- data/lib/picky/backends/redis/basic.rb +12 -9
- data/lib/picky/backends/redis.rb +10 -4
- data/lib/picky/bundle.rb +14 -0
- data/lib/picky/bundle_indexed.rb +110 -0
- data/lib/picky/bundle_indexing.rb +177 -0
- data/lib/picky/bundle_realtime.rb +80 -0
- data/lib/picky/categories.rb +5 -1
- data/lib/picky/category.rb +12 -20
- data/lib/picky/category_indexed.rb +3 -6
- data/lib/picky/category_indexing.rb +19 -18
- data/lib/picky/category_realtime.rb +5 -10
- data/lib/picky/extensions/symbol.rb +1 -1
- data/lib/picky/generators/partial/default.rb +1 -1
- data/lib/picky/generators/partial/postfix.rb +30 -0
- data/lib/picky/generators/partial/substring.rb +8 -2
- data/lib/picky/index.rb +3 -3
- data/lib/picky/index_indexing.rb +3 -2
- data/lib/picky/indexers/base.rb +0 -8
- data/lib/picky/indexers/parallel.rb +1 -1
- data/lib/picky/loader.rb +15 -15
- data/lib/picky/query/qualifier_category_mapper.rb +1 -1
- data/lib/picky/rack/harakiri.rb +3 -1
- data/lib/picky/sources/db.rb +11 -0
- data/lib/picky/statistics.rb +2 -2
- data/lib/picky/tokenizer.rb +1 -1
- data/lib/picky/tokenizers/location.rb +1 -1
- data/lib/picky/wrappers/bundle/calculation.rb +45 -0
- data/lib/picky/wrappers/bundle/delegators.rb +69 -0
- data/lib/picky/wrappers/bundle/exact_partial.rb +38 -0
- data/lib/picky/{indexed/wrappers → wrappers}/bundle/location.rb +6 -4
- data/lib/picky/wrappers/bundle/wrapper.rb +29 -0
- data/lib/picky/wrappers/category/exact_first.rb +55 -0
- data/lib/picky/wrappers/category/location.rb +33 -0
- data/lib/picky/{sources/wrappers → wrappers/sources}/base.rb +7 -3
- data/lib/picky/{sources/wrappers → wrappers/sources}/location.rb +3 -3
- data/lib/picky.rb +10 -11
- data/spec/aux/picky/cli_spec.rb +5 -5
- data/spec/lib/backends/backend_spec.rb +39 -0
- data/spec/lib/backends/file/basic_spec.rb +59 -0
- data/spec/lib/backends/file_spec.rb +105 -0
- data/spec/lib/backends/memory/basic_spec.rb +43 -15
- data/spec/lib/backends/memory_spec.rb +108 -54
- data/spec/lib/backends/redis/basic_spec.rb +81 -57
- data/spec/lib/backends/redis_spec.rb +120 -66
- data/spec/lib/category_indexed_spec.rb +12 -12
- data/spec/lib/category_indexing_spec.rb +23 -23
- data/spec/lib/category_spec.rb +14 -14
- data/spec/lib/cores_spec.rb +2 -2
- data/spec/lib/extensions/object_spec.rb +7 -7
- data/spec/lib/generators/partial/postfix_spec.rb +131 -0
- data/spec/lib/generators/partial/substring_spec.rb +29 -4
- data/spec/lib/generators/weights_generator_spec.rb +3 -3
- data/spec/lib/index_indexing_spec.rb +11 -15
- data/spec/lib/index_spec.rb +8 -8
- data/spec/lib/indexed/bundle_realtime_spec.rb +18 -18
- data/spec/lib/indexed/bundle_spec.rb +21 -21
- data/spec/lib/indexed/wrappers/bundle/calculation_spec.rb +9 -9
- data/spec/lib/indexed/wrappers/bundle/wrapper_spec.rb +8 -8
- data/spec/lib/indexed/wrappers/exact_first_spec.rb +16 -16
- data/spec/lib/indexers/base_spec.rb +6 -25
- data/spec/lib/indexes_spec.rb +33 -22
- data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +2 -2
- data/spec/lib/indexing/bundle_spec.rb +27 -28
- data/spec/lib/sources/wrappers/base_spec.rb +7 -7
- data/spec/lib/sources/wrappers/location_spec.rb +8 -8
- metadata +48 -38
- data/lib/picky/indexed/bundle.rb +0 -125
- data/lib/picky/indexed/bundle_realtime.rb +0 -76
- data/lib/picky/indexed/wrappers/bundle/calculation.rb +0 -47
- data/lib/picky/indexed/wrappers/bundle/wrapper.rb +0 -47
- data/lib/picky/indexed/wrappers/category/location.rb +0 -31
- data/lib/picky/indexed/wrappers/exact_first.rb +0 -59
- data/lib/picky/indexing/bundle.rb +0 -183
- 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
|
-
|
6
|
-
|
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
|
-
|
9
|
-
|
12
|
+
@backend.stub! :timed_exclaim
|
13
|
+
end
|
10
14
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
31
|
+
context 'with lambda options' do
|
27
32
|
before(:each) do
|
28
|
-
@
|
29
|
-
|
30
|
-
|
31
|
-
|
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.
|
38
|
+
@backend.stub! :timed_exclaim
|
39
39
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
61
|
+
@backend.stub! :timed_exclaim
|
60
62
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
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
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
37
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
56
|
-
|
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
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
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
|
-
|
70
|
-
|
71
|
-
client
|
72
|
-
|
73
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
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
|
-
|
6
|
-
|
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
|
-
|
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
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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.
|
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.
|
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.
|
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.
|
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! :
|
146
|
-
@category.stub! :
|
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
|