picky 3.0.1 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/lib/picky/application.rb +12 -12
  2. data/lib/picky/backends/backend.rb +17 -0
  3. data/lib/picky/{backend → backends}/file/basic.rb +1 -1
  4. data/lib/picky/{backend → backends}/file/json.rb +1 -1
  5. data/lib/picky/{backend → backends}/file/marshal.rb +1 -1
  6. data/lib/picky/{backend → backends}/file/text.rb +1 -1
  7. data/lib/picky/backends/memory.rb +53 -0
  8. data/lib/picky/{backend → backends}/redis/basic.rb +9 -14
  9. data/lib/picky/backends/redis/float_hash.rb +26 -0
  10. data/lib/picky/{backend → backends}/redis/list_hash.rb +7 -11
  11. data/lib/picky/{backend → backends}/redis/string_hash.rb +7 -11
  12. data/lib/picky/backends/redis.rb +87 -0
  13. data/lib/picky/bundle.rb +107 -11
  14. data/lib/picky/category.rb +5 -5
  15. data/lib/picky/index.rb +329 -0
  16. data/lib/picky/index_indexed.rb +31 -0
  17. data/lib/picky/index_indexing.rb +161 -0
  18. data/lib/picky/indexed/bundle.rb +112 -0
  19. data/lib/picky/indexed/wrappers/exact_first.rb +1 -1
  20. data/lib/picky/indexers/parallel.rb +2 -1
  21. data/lib/picky/indexers/serial.rb +2 -1
  22. data/lib/picky/indexes_indexing.rb +1 -1
  23. data/lib/picky/indexing/bundle.rb +188 -0
  24. data/lib/picky/indexing/wrappers/category/location.rb +1 -1
  25. data/lib/picky/interfaces/live_parameters.rb +8 -8
  26. data/lib/picky/loader.rb +24 -38
  27. data/lib/picky/migrations/from_30_to_31.rb +61 -0
  28. data/lib/picky/query/allocation.rb +10 -5
  29. data/lib/picky/query/combinations.rb +70 -0
  30. data/lib/picky/query/indexes.rb +8 -7
  31. data/lib/picky/query/indexes_check.rb +47 -0
  32. data/lib/picky/query/token.rb +16 -29
  33. data/lib/picky/query/tokens.rb +4 -20
  34. data/lib/picky/search.rb +51 -58
  35. data/lib/picky/tokenizer.rb +231 -0
  36. data/lib/picky/tokenizers/location.rb +1 -1
  37. data/lib/tasks/try.rake +4 -12
  38. data/lib/tasks/try.rb +37 -0
  39. data/spec/lib/application_spec.rb +5 -5
  40. data/spec/lib/{backend → backends}/file/basic_spec.rb +2 -2
  41. data/spec/lib/{backend → backends}/file/json_spec.rb +2 -2
  42. data/spec/lib/{backend → backends}/file/marshal_spec.rb +2 -2
  43. data/spec/lib/{backend → backends}/file/text_spec.rb +1 -1
  44. data/spec/lib/backends/memory_spec.rb +77 -0
  45. data/spec/lib/{backend → backends}/redis/basic_spec.rb +19 -21
  46. data/spec/lib/backends/redis/float_hash_spec.rb +38 -0
  47. data/spec/lib/backends/redis/list_hash_spec.rb +27 -0
  48. data/spec/lib/backends/redis/string_hash_spec.rb +38 -0
  49. data/spec/lib/backends/redis_spec.rb +79 -0
  50. data/spec/lib/categories_indexed_spec.rb +3 -3
  51. data/spec/lib/category_indexed_spec.rb +6 -6
  52. data/spec/lib/category_indexing_spec.rb +1 -1
  53. data/spec/lib/category_spec.rb +1 -1
  54. data/spec/lib/frontend_adapters/rack_spec.rb +2 -2
  55. data/spec/lib/{indexes/index_indexed_spec.rb → index_indexed_spec.rb} +1 -1
  56. data/spec/lib/{indexes/index_indexing_spec.rb → index_indexing_spec.rb} +1 -1
  57. data/spec/lib/{indexes/index_spec.rb → index_spec.rb} +1 -1
  58. data/spec/lib/indexed/{bundle/memory_spec.rb → memory_spec.rb} +18 -18
  59. data/spec/lib/indexed/wrappers/exact_first_spec.rb +2 -2
  60. data/spec/lib/indexing/{bundle/memory_partial_generation_speed_spec.rb → bundle_partial_generation_speed_spec.rb} +3 -3
  61. data/spec/lib/indexing/bundle_spec.rb +302 -0
  62. data/spec/lib/query/allocation_spec.rb +21 -11
  63. data/spec/lib/query/combination_spec.rb +2 -2
  64. data/spec/lib/query/{combinations/base_spec.rb → combinations_spec.rb} +1 -1
  65. data/spec/lib/query/indexes_check_spec.rb +25 -0
  66. data/spec/lib/query/indexes_spec.rb +5 -1
  67. data/spec/lib/query/token_spec.rb +18 -20
  68. data/spec/lib/query/tokens_spec.rb +14 -65
  69. data/spec/lib/search_spec.rb +36 -37
  70. data/spec/lib/tasks/try_spec.rb +51 -0
  71. data/spec/lib/{tokenizers/base_spec.rb → tokenizer_spec.rb} +15 -44
  72. metadata +64 -81
  73. data/lib/picky/backend/base.rb +0 -121
  74. data/lib/picky/backend/files.rb +0 -28
  75. data/lib/picky/backend/redis.rb +0 -44
  76. data/lib/picky/indexed/bundle/base.rb +0 -47
  77. data/lib/picky/indexed/bundle/memory.rb +0 -88
  78. data/lib/picky/indexed/bundle/redis.rb +0 -91
  79. data/lib/picky/indexes/index.rb +0 -328
  80. data/lib/picky/indexes/index_indexed.rb +0 -35
  81. data/lib/picky/indexes/index_indexing.rb +0 -165
  82. data/lib/picky/indexes/memory.rb +0 -20
  83. data/lib/picky/indexes/redis.rb +0 -20
  84. data/lib/picky/indexing/bundle/base.rb +0 -242
  85. data/lib/picky/indexing/bundle/memory.rb +0 -26
  86. data/lib/picky/indexing/bundle/redis.rb +0 -26
  87. data/lib/picky/query/combinations/base.rb +0 -74
  88. data/lib/picky/query/combinations/memory.rb +0 -52
  89. data/lib/picky/query/combinations/redis.rb +0 -90
  90. data/lib/picky/query.rb +0 -6
  91. data/lib/picky/tokenizers/base.rb +0 -231
  92. data/lib/picky/tokenizers/index.rb +0 -34
  93. data/lib/picky/tokenizers/query.rb +0 -61
  94. data/spec/lib/backend/files_spec.rb +0 -189
  95. data/spec/lib/backend/redis/list_hash_spec.rb +0 -40
  96. data/spec/lib/backend/redis/string_hash_spec.rb +0 -47
  97. data/spec/lib/backend/redis_spec.rb +0 -170
  98. data/spec/lib/indexed/bundle/redis_spec.rb +0 -41
  99. data/spec/lib/indexes/redis_spec.rb +0 -15
  100. data/spec/lib/indexing/bundle/base_spec.rb +0 -38
  101. data/spec/lib/indexing/bundle/memory_spec.rb +0 -287
  102. data/spec/lib/indexing/bundle/redis_spec.rb +0 -283
  103. data/spec/lib/query/combinations/memory_spec.rb +0 -158
  104. data/spec/lib/query/combinations/redis_spec.rb +0 -172
  105. data/spec/lib/tokenizers/index_spec.rb +0 -69
  106. data/spec/lib/tokenizers/query_spec.rb +0 -121
@@ -0,0 +1,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::Memory do
4
+
5
+ before(:each) do
6
+ @backend = described_class.new
7
+
8
+ @backend.stub! :timed_exclaim
9
+ end
10
+
11
+ describe 'create_...' do
12
+ [
13
+ [:inverted, Picky::Backends::File::JSON],
14
+ [:weights, Picky::Backends::File::JSON],
15
+ [:similarity, Picky::Backends::File::Marshal],
16
+ [:configuration, Picky::Backends::File::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)
22
+ end
23
+ end
24
+ end
25
+
26
+ describe "ids" do
27
+ 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
37
+
38
+ @backend.ids(@combinations, :any, :thing).should == (1..10).to_a
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
46
+ 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
51
+
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
58
+
59
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.004
60
+ 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
67
+ 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
72
+
73
+ performance_of { @backend.ids(@combinations, :any, :thing) }.should < 0.0001
74
+ end
75
+ end
76
+
77
+ end
@@ -1,35 +1,36 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Backend::Redis::Basic do
3
+ describe Picky::Backends::Redis::Basic do
4
4
 
5
- let(:redis) { described_class.new "some_namespace" }
5
+ let(:client) { stub :client }
6
+ let(:index) { described_class.new client, :some_namespace }
6
7
 
7
8
  describe 'load, retrieve, backup, delete' do
8
9
  it 'is nothing they do (at least on the backend)' do
9
- redis.should_receive(:backend).never
10
+ index.should_receive(:client).never
10
11
 
11
- redis.load
12
- redis.retrieve
13
- redis.backup
14
- redis.delete
12
+ index.load
13
+ index.retrieve
14
+ index.backup
15
+ index.delete
15
16
  end
16
17
  end
17
18
 
18
19
  describe 'cache_small?' do
19
20
  context 'size 0' do
20
21
  before(:each) do
21
- redis.stub! :size => 0
22
+ index.stub! :size => 0
22
23
  end
23
24
  it 'is small' do
24
- redis.cache_small?.should == true
25
+ index.cache_small?.should == true
25
26
  end
26
27
  end
27
28
  context 'size 1' do
28
29
  before(:each) do
29
- redis.stub! :size => 1
30
+ index.stub! :size => 1
30
31
  end
31
32
  it 'is not small' do
32
- redis.cache_small?.should == false
33
+ index.cache_small?.should == false
33
34
  end
34
35
  end
35
36
  end
@@ -37,36 +38,33 @@ describe Picky::Backend::Redis::Basic do
37
38
  describe 'cache_ok?' do
38
39
  context 'size 0' do
39
40
  before(:each) do
40
- redis.stub! :size => 0
41
+ index.stub! :size => 0
41
42
  end
42
43
  it 'is not ok' do
43
- redis.cache_ok?.should == false
44
+ index.cache_ok?.should == false
44
45
  end
45
46
  end
46
47
  context 'size 1' do
47
48
  before(:each) do
48
- redis.stub! :size => 1
49
+ index.stub! :size => 1
49
50
  end
50
51
  it 'is ok' do
51
- redis.cache_ok?.should == true
52
+ index.cache_ok?.should == true
52
53
  end
53
54
  end
54
55
  end
55
56
 
56
57
  describe "size" do
57
58
  it 'delegates to the backend' do
58
- backend = stub :backend
59
- redis.stub! :backend => backend
59
+ client.should_receive(:dbsize).once.with
60
60
 
61
- backend.should_receive(:dbsize).once.with
62
-
63
- redis.size
61
+ index.size
64
62
  end
65
63
  end
66
64
 
67
65
  describe 'to_s' do
68
66
  it 'returns the cache path with the default file extension' do
69
- redis.to_s.should == 'Picky::Backend::Redis::Basic(some_namespace:*)'
67
+ index.to_s.should == 'Picky::Backends::Redis::Basic(some_namespace:*)'
70
68
  end
71
69
  end
72
70
 
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::Redis::FloatHash do
4
+
5
+ let(:client) { stub :client }
6
+ let(:backend) { described_class.new client, :some_namespace }
7
+
8
+ describe 'dump' do
9
+ it 'dumps correctly' do
10
+ client.should_receive(:del).once.ordered.with :some_namespace
11
+ client.should_receive(:hset).once.ordered.with :some_namespace, :a, 1
12
+ client.should_receive(:hset).once.ordered.with :some_namespace, :b, 2
13
+ client.should_receive(:hset).once.ordered.with :some_namespace, :c, 3
14
+
15
+ backend.dump a: 1, b: 2, c: 3
16
+ end
17
+ end
18
+
19
+ describe 'member' do
20
+ it 'delegates to the backend' do
21
+ client.should_receive(:hget).once.with :some_namespace, :some_symbol
22
+
23
+ backend[:some_symbol]
24
+ end
25
+ it 'returns whatever it gets from the backend' do
26
+ client.should_receive(:hget).any_number_of_times.and_return '1.23'
27
+
28
+ backend[:anything].should == 1.23
29
+ end
30
+ end
31
+
32
+ describe 'to_s' do
33
+ it 'returns the cache path with the default file extension' do
34
+ backend.to_s.should == 'Picky::Backends::Redis::FloatHash(some_namespace:*)'
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::Redis::ListHash do
4
+
5
+ let(:client) { stub :client }
6
+ let(:index) { described_class.new client, :some_namespace }
7
+
8
+ describe '[]' do
9
+ it 'returns whatever comes back from the backend' do
10
+ client.stub! :zrange => :some_lrange_result
11
+
12
+ index[:anything].should == :some_lrange_result
13
+ end
14
+ it 'calls the right method on the backend' do
15
+ client.should_receive(:zrange).once.with "some_namespace:some_sym", 0, -1
16
+
17
+ index[:some_sym]
18
+ end
19
+ end
20
+
21
+ describe 'to_s' do
22
+ it 'returns the cache path with the default file extension' do
23
+ index.to_s.should == 'Picky::Backends::Redis::ListHash(some_namespace:*)'
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::Redis::StringHash do
4
+
5
+ let(:client) { stub :client }
6
+ let(:backend) { described_class.new client, :some_namespace }
7
+
8
+ describe 'dump' do
9
+ it 'dumps correctly' do
10
+ client.should_receive(:del).once.ordered.with :some_namespace
11
+ client.should_receive(:hset).once.ordered.with :some_namespace, :a, 1
12
+ client.should_receive(:hset).once.ordered.with :some_namespace, :b, 2
13
+ client.should_receive(:hset).once.ordered.with :some_namespace, :c, 3
14
+
15
+ backend.dump a: 1, b: 2, c: 3
16
+ end
17
+ end
18
+
19
+ describe 'member' do
20
+ it 'delegates to the backend' do
21
+ client.should_receive(:hget).once.with :some_namespace, :some_symbol
22
+
23
+ backend[:some_symbol]
24
+ end
25
+ it 'returns whatever it gets from the backend' do
26
+ client.should_receive(:hget).any_number_of_times.and_return :some_result
27
+
28
+ backend[:anything].should == :some_result
29
+ end
30
+ end
31
+
32
+ describe 'to_s' do
33
+ it 'returns the cache path with the default file extension' do
34
+ backend.to_s.should == 'Picky::Backends::Redis::StringHash(some_namespace:*)'
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Picky::Backends::Redis do
4
+
5
+ before(:each) do
6
+ @backend = described_class.new
7
+
8
+ @backend.stub! :timed_exclaim
9
+ end
10
+
11
+ describe 'create_...' do
12
+ [
13
+ [:inverted, Picky::Backends::Redis::ListHash],
14
+ [:weights, Picky::Backends::Redis::FloatHash],
15
+ [:similarity, Picky::Backends::Redis::ListHash],
16
+ [:configuration, Picky::Backends::Redis::StringHash]
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)
22
+ end
23
+ end
24
+ end
25
+
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
78
+
79
+ end
@@ -22,7 +22,7 @@ describe Picky::Categories do
22
22
 
23
23
  context "with real categories" do
24
24
  before(:each) do
25
- @index1 = Picky::Indexes::Memory.new :name
25
+ @index1 = Picky::Index.new :name
26
26
 
27
27
  @categories = described_class.new
28
28
  @categories << Picky::Category.new(:category1, @index1)
@@ -31,7 +31,7 @@ describe Picky::Categories do
31
31
  end
32
32
  describe "similar_possible_for" do
33
33
  before(:each) do
34
- @token = Picky::Query::Token.processed 'similar~'
34
+ @token = Picky::Query::Token.processed 'similar~', 'Similar~'
35
35
  end
36
36
  it "returns possible categories" do
37
37
  @categories.similar_possible_for(@token).should == []
@@ -65,7 +65,7 @@ describe Picky::Categories do
65
65
 
66
66
  context 'without options' do
67
67
  before(:each) do
68
- @index1 = Picky::Indexes::Memory.new :some_index
68
+ @index1 = Picky::Index.new :some_index
69
69
 
70
70
  @category1 = Picky::Category.new :category1, @index1
71
71
  @category2 = Picky::Category.new :category2, @index1
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Picky::Category do
4
4
 
5
5
  before(:each) do
6
- @index = Picky::Indexes::Index.new :some_index do
6
+ @index = Picky::Index.new :some_index do
7
7
  source []
8
8
  end
9
9
  @partial_strategy = stub :partial, :use_exact_for_partial? => false
@@ -31,18 +31,18 @@ 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::Memory)
34
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::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::Memory)
39
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle)
40
40
  end
41
41
  end
42
42
  end
43
43
  context 'indexed_bundle_class defined differently' do
44
44
  before(:each) do
45
- index = Picky::Indexes::Redis.new(:some_index_name) do
45
+ index = Picky::Index.new(:some_index_name) do
46
46
  source []
47
47
  end
48
48
  @category = described_class.new :some_name, index
@@ -52,12 +52,12 @@ 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::Redis)
55
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::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::Redis)
60
+ @category.indexed_partial.should be_kind_of(Picky::Indexed::Bundle)
61
61
  end
62
62
  end
63
63
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Picky::Category do
4
4
 
5
5
  before(:each) do
6
- @index = Picky::Indexes::Memory.new :some_index
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 } }
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Category do
4
4
 
5
- let(:index) { Picky::Indexes::Memory.new :some_index }
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
@@ -54,7 +54,7 @@ describe Picky::FrontendAdapters::Rack do
54
54
  end
55
55
  describe 'to_s' do
56
56
  it 'outputs correctly' do
57
- @rack_adapter.to_s.should == "Note: Anchored (✓) regexps are faster, e.g. /\\A.*\\Z/ or /^.*$/.\n\n something => Picky::Search()"
57
+ @rack_adapter.to_s.should == "Note: Anchored (✓) regexps are faster, e.g. /\\A.*\\Z/ or /^.*$/.\n\n something => Picky::Search(weights: Picky::Query::Weights({}))"
58
58
  end
59
59
  end
60
60
  end
@@ -63,7 +63,7 @@ describe Picky::FrontendAdapters::Rack do
63
63
  context 'real routes' do
64
64
  before(:each) do
65
65
  @rack_adapter.reset_routes
66
- Picky.logger.stub! :log
66
+ Picky.logger.stub! :info
67
67
  end
68
68
  it 'should route correctly' do
69
69
  env = {}
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Indexes::Index do
3
+ describe Picky::Index do
4
4
 
5
5
  context 'without stubbed categories' do
6
6
  before(:each) do
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Indexes::Index do
3
+ describe Picky::Index do
4
4
 
5
5
  describe 'tokenizer' do
6
6
  context 'with tokenizer' do
@@ -2,7 +2,7 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe Picky::Indexes::Index do
5
+ describe Picky::Index do
6
6
 
7
7
  let(:some_source) { stub :source, :harvest => nil, :inspect => 'some_source' }
8
8
 
@@ -1,27 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Indexed::Bundle::Memory do
3
+ describe Picky::Indexed::Bundle do
4
4
 
5
5
  before(:each) do
6
- @index = Picky::Indexes::Memory.new :some_index
6
+ @index = Picky::Index.new :some_index
7
7
  @category = Picky::Category.new :some_category, @index
8
8
 
9
9
  @similarity = stub :similarity
10
- @bundle = described_class.new :some_name, @category, @similarity
10
+ @bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, @similarity
11
11
  end
12
12
 
13
13
  describe 'to_s' do
14
14
  it 'does something' do
15
- @bundle.to_s.should == "Picky::Indexed::Bundle::Memory(test:some_index:some_category:some_name)"
15
+ @bundle.to_s.should == "Picky::Indexed::Bundle(test:some_index:some_category:some_name)"
16
16
  end
17
17
  end
18
18
 
19
19
  describe 'clear_index' do
20
20
  before(:each) do
21
- @bundle.instance_variable_set(:@inverted, :not_empty)
21
+ @bundle.instance_variable_set :@inverted, { :a => [] }
22
22
  end
23
23
  it 'has not cleared the inverted index' do
24
- @bundle.inverted.should == :not_empty
24
+ @bundle.inverted.should == { :a => [] }
25
25
  end
26
26
  it 'clears the inverted index' do
27
27
  @bundle.clear_inverted
@@ -31,10 +31,10 @@ describe Picky::Indexed::Bundle::Memory do
31
31
  end
32
32
  describe 'clear_weights' do
33
33
  before(:each) do
34
- @bundle.instance_variable_set(:@weights, :not_empty)
34
+ @bundle.instance_variable_set :@weights, { :a => 1.0 }
35
35
  end
36
36
  it 'has not cleared the weights' do
37
- @bundle.weights.should == :not_empty
37
+ @bundle.weights.should == { :a => 1.0 }
38
38
  end
39
39
  it 'clears the weights' do
40
40
  @bundle.clear_weights
@@ -44,10 +44,10 @@ describe Picky::Indexed::Bundle::Memory do
44
44
  end
45
45
  describe 'clear_similarity' do
46
46
  before(:each) do
47
- @bundle.instance_variable_set(:@similarity, :not_empty)
47
+ @bundle.instance_variable_set :@similarity, { :a => :aa }
48
48
  end
49
49
  it 'has not cleared the similarity index' do
50
- @bundle.similarity.should == :not_empty
50
+ @bundle.similarity.should == { :a => :aa }
51
51
  end
52
52
  it 'clears the similarity index' do
53
53
  @bundle.clear_similarity
@@ -57,10 +57,10 @@ describe Picky::Indexed::Bundle::Memory do
57
57
  end
58
58
  describe 'clear_configuration' do
59
59
  before(:each) do
60
- @bundle.instance_variable_set(:@configuration, :not_empty)
60
+ @bundle.instance_variable_set :@configuration, { :a => 'value' }
61
61
  end
62
62
  it 'has not cleared the similarity index' do
63
- @bundle.configuration.should == :not_empty
63
+ @bundle.configuration.should == { :a => 'value' }
64
64
  end
65
65
  it 'clears the similarity index' do
66
66
  @bundle.clear_configuration
@@ -153,22 +153,22 @@ describe Picky::Indexed::Bundle::Memory do
153
153
 
154
154
  describe 'initialization' do
155
155
  before(:each) do
156
- @index = Picky::Indexes::Memory.new :some_index
156
+ @index = Picky::Index.new :some_index
157
157
  @category = Picky::Category.new :some_category, @index
158
158
 
159
- @bundle = described_class.new :some_name, @category, :similarity
159
+ @bundle = described_class.new :some_name, @category, Picky::Backends::Memory.new, :similarity
160
160
  end
161
161
  it 'should initialize the index correctly' do
162
- @bundle.inverted.should == {}
162
+ @bundle.backend_inverted.should be_kind_of(Picky::Backends::File::JSON)
163
163
  end
164
164
  it 'should initialize the weights index correctly' do
165
- @bundle.weights.should == {}
165
+ @bundle.backend_weights.should be_kind_of(Picky::Backends::File::JSON)
166
166
  end
167
167
  it 'should initialize the similarity index correctly' do
168
- @bundle.similarity.should == {}
168
+ @bundle.backend_similarity.should be_kind_of(Picky::Backends::File::Marshal)
169
169
  end
170
170
  it 'should initialize the configuration correctly' do
171
- @bundle.configuration.should == {}
171
+ @bundle.backend_configuration.should be_kind_of(Picky::Backends::File::JSON)
172
172
  end
173
173
  it 'should initialize the similarity strategy correctly' do
174
174
  @bundle.similarity_strategy.should == :similarity
@@ -13,7 +13,7 @@ describe Picky::Indexed::Wrappers::ExactFirst do
13
13
  describe "self.wrap" do
14
14
  context "index" do
15
15
  it "wraps each category" do
16
- index = Picky::Indexes::Memory.new :some_index
16
+ index = Picky::Index.new :some_index
17
17
  index.define_category :some_category
18
18
 
19
19
  Picky::Indexed::Wrappers::ExactFirst.wrap index
@@ -23,7 +23,7 @@ describe Picky::Indexed::Wrappers::ExactFirst do
23
23
  end
24
24
  end
25
25
  it "returns the index" do
26
- index = Picky::Indexes::Memory.new :some_index
26
+ index = Picky::Index.new :some_index
27
27
  index.define_category :some_category
28
28
 
29
29
  described_class.wrap(index).should == index
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Picky::Indexing::Bundle::Memory do
3
+ describe Picky::Indexing::Bundle do
4
4
 
5
5
  before(:each) do
6
- @index = Picky::Indexes::Memory.new :some_index
6
+ @index = Picky::Index.new :some_index
7
7
  @category = Picky::Category.new :some_category, @index
8
8
 
9
9
  @partial_strategy = Picky::Generators::Partial::Substring.new :from => 1
10
- @exact = described_class.new :some_name, @category, nil, @partial_strategy, nil
10
+ @exact = described_class.new :some_name, @category, Picky::Backends::Memory.new, nil, @partial_strategy, nil
11
11
  end
12
12
 
13
13
  def generate_random_keys amount