picky 2.6.0 → 2.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. data/lib/picky/analyzer.rb +4 -4
  2. data/lib/picky/application.rb +6 -7
  3. data/lib/picky/backend/{backend.rb → base.rb} +31 -14
  4. data/lib/picky/backend/file/basic.rb +12 -4
  5. data/lib/picky/backend/file/json.rb +5 -5
  6. data/lib/picky/backend/file/text.rb +1 -1
  7. data/lib/picky/backend/files.rb +3 -9
  8. data/lib/picky/backend/redis/basic.rb +8 -0
  9. data/lib/picky/backend/redis/list_hash.rb +5 -5
  10. data/lib/picky/backend/redis/string_hash.rb +5 -5
  11. data/lib/picky/backend/redis.rb +5 -5
  12. data/lib/picky/bundle.rb +62 -0
  13. data/lib/picky/categories.rb +10 -9
  14. data/lib/picky/categories_indexed.rb +12 -7
  15. data/lib/picky/categories_indexing.rb +7 -9
  16. data/lib/picky/category.rb +38 -26
  17. data/lib/picky/category_indexed.rb +4 -20
  18. data/lib/picky/category_indexing.rb +71 -68
  19. data/lib/picky/generators/base.rb +6 -6
  20. data/lib/picky/generators/partial/substring.rb +28 -26
  21. data/lib/picky/generators/partial_generator.rb +3 -3
  22. data/lib/picky/generators/similarity/phonetic.rb +5 -5
  23. data/lib/picky/generators/similarity_generator.rb +2 -2
  24. data/lib/picky/generators/weights/logarithmic.rb +3 -3
  25. data/lib/picky/generators/weights_generator.rb +2 -2
  26. data/lib/picky/index/base.rb +13 -10
  27. data/lib/picky/index/base_indexed.rb +2 -0
  28. data/lib/picky/index/base_indexing.rb +65 -57
  29. data/lib/picky/indexed/bundle/base.rb +21 -86
  30. data/lib/picky/indexed/bundle/memory.rb +5 -12
  31. data/lib/picky/indexed/bundle/redis.rb +42 -0
  32. data/lib/picky/indexed/wrappers/bundle/wrapper.rb +3 -3
  33. data/lib/picky/indexers/base.rb +20 -3
  34. data/lib/picky/indexers/parallel.rb +32 -14
  35. data/lib/picky/indexers/serial.rb +29 -26
  36. data/lib/picky/indexes.rb +5 -3
  37. data/lib/picky/indexes_indexed.rb +3 -15
  38. data/lib/picky/indexes_indexing.rb +18 -21
  39. data/lib/picky/indexing/bundle/base.rb +64 -45
  40. data/lib/picky/indexing/bundle/memory.rb +0 -4
  41. data/lib/picky/loader.rb +7 -6
  42. data/lib/picky/query/allocation.rb +3 -3
  43. data/lib/picky/query/token.rb +5 -1
  44. data/lib/picky/search.rb +5 -0
  45. data/lib/picky/sources/base.rb +21 -2
  46. data/lib/picky/sources/db.rb +0 -7
  47. data/lib/picky/statistics.rb +9 -12
  48. data/lib/picky/tokenizers/location.rb +1 -1
  49. data/lib/tasks/checks.rake +8 -6
  50. data/lib/tasks/index.rake +14 -20
  51. data/lib/tasks/server.rake +18 -2
  52. data/lib/tasks/statistics.rake +27 -14
  53. data/lib/tasks/todo.rake +2 -2
  54. data/lib/tasks/try.rake +12 -27
  55. data/spec/lib/application_spec.rb +1 -1
  56. data/spec/lib/backend/file/basic_spec.rb +6 -6
  57. data/spec/lib/backend/file/json_spec.rb +11 -6
  58. data/spec/lib/backend/file/marshal_spec.rb +11 -6
  59. data/spec/lib/backend/files_spec.rb +21 -7
  60. data/spec/lib/backend/redis/basic_spec.rb +6 -0
  61. data/spec/lib/backend/redis/list_hash_spec.rb +9 -3
  62. data/spec/lib/backend/redis/string_hash_spec.rb +7 -1
  63. data/spec/lib/backend/redis_spec.rb +22 -12
  64. data/spec/lib/categories_indexed_spec.rb +2 -2
  65. data/spec/lib/category_indexing_spec.rb +12 -33
  66. data/spec/lib/category_spec.rb +22 -0
  67. data/spec/lib/index/base_indexing_spec.rb +30 -0
  68. data/spec/lib/indexed/bundle/memory_spec.rb +13 -20
  69. data/spec/lib/indexers/base_spec.rb +39 -4
  70. data/spec/lib/indexers/parallel_spec.rb +2 -10
  71. data/spec/lib/indexers/serial_spec.rb +11 -26
  72. data/spec/lib/indexes_class_spec.rb +4 -4
  73. data/spec/lib/indexes_indexed_spec.rb +2 -2
  74. data/spec/lib/indexes_indexing_spec.rb +6 -10
  75. data/spec/lib/indexes_spec.rb +3 -3
  76. data/spec/lib/indexing/bundle/{super_base_spec.rb → base_spec.rb} +2 -2
  77. data/spec/lib/indexing/bundle/memory_partial_generation_speed_spec.rb +3 -3
  78. data/spec/lib/indexing/bundle/memory_spec.rb +16 -14
  79. data/spec/lib/indexing/bundle/redis_spec.rb +18 -16
  80. data/spec/lib/query/allocation_spec.rb +1 -1
  81. data/spec/lib/query/token_spec.rb +5 -7
  82. data/spec/lib/sources/base_spec.rb +53 -0
  83. data/spec/lib/sources/db_spec.rb +0 -7
  84. metadata +11 -12
  85. data/lib/picky/indexers/solr.rb +0 -56
  86. data/lib/picky/indexing/bundle/super_base.rb +0 -61
  87. data/lib/picky/solr/schema_generator.rb +0 -74
  88. data/lib/tasks/search.rake +0 -9
  89. data/lib/tasks/shortcuts.rake +0 -32
  90. data/lib/tasks/solr.rake +0 -36
data/lib/tasks/try.rake CHANGED
@@ -1,34 +1,19 @@
1
1
  # Tasks for manually testing your engine configuration.
2
2
  #
3
- namespace :try do
3
+ desc "Try the given text in the indexer/query (index and category optional)."
4
+ task :try, [:text, :index, :category] => :application do |_, options|
5
+ text, index, category = options.text, options.index, options.category
4
6
 
5
- # desc "Try how a given word would be tokenized when indexing (type:category optional)."
6
- task :index, [:text, :index, :category] => :application do |_, options|
7
- text, index, category = options.text, options.index, options.category
7
+ puts
8
+ fail "\x1b[31mrake try needs a text to try indexing and query preparation\x1b[m, e.g. rake 'try[yourtext]'." unless text
8
9
 
9
- tokenizer = category ? Indexes.find(index, category).tokenizer : Tokenizers::Index.default
10
+ specific = Indexes
11
+ specific = specific[index] if index
12
+ specific = specific[category] if category
10
13
 
11
- puts "\"#{text}\" is saved in the index as #{tokenizer.tokenize(text.dup).to_a}"
12
- end
13
-
14
- # desc "Try how a given word would be tokenized when querying."
15
- task :query, [:text] => :application do |_, options|
16
- text = options.text
17
-
18
- puts "\"#{text}\" as a search will be preprocessed into #{Tokenizers::Query.default.tokenize(text.dup).to_a.map(&:to_s).map(&:to_sym)}"
19
- puts
20
- puts "(category qualifiers, e.g. title: are removed if they do not exist as a qualifier, so 'toitle:bla' -> 'bla')"
21
- end
22
-
23
- # desc "Try the given text with both the index and the query (type:category optional)."
24
- task :both, [:text, :index, :category] => :application do |_, options|
25
- text, index, category = options.text, options.index, options.category
26
-
27
- puts
28
- fail "\x1b[31mrake try needs a text to try indexing and query preparation\x1b[m, e.g. rake 'try[yourtext]'." unless text
29
-
30
- Rake::Task[:"try:index"].invoke text, index, category
31
- Rake::Task[:"try:query"].invoke text
32
- end
14
+ puts "\"#{text}\" is saved in the #{specific.identifier} index as #{specific.tokenizer.tokenize(text.dup).to_a}"
33
15
 
16
+ puts "\"#{text}\" as a search will be tokenized into #{Tokenizers::Query.default.tokenize(text.dup).to_a.map(&:to_s).map(&:to_sym)}"
17
+ puts
18
+ puts "(category qualifiers, e.g. title: are removed if they do not exist as a qualifier, so 'toitle:bla' -> 'bla')"
34
19
  end
@@ -37,7 +37,7 @@ describe Application do
37
37
  normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']],
38
38
 
39
39
  substitutes_characters_with: CharacterSubstituters::WestEuropean.new,
40
- maximum_tokens: 5 # TODO maximum_words?
40
+ maximum_tokens: 5
41
41
 
42
42
  books_index = Index::Memory.new :books,
43
43
  source: Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
@@ -10,16 +10,16 @@ describe Backend::File::Basic do
10
10
  end
11
11
  end
12
12
 
13
- describe 'to_s' do
14
- it 'returns the cache path with the default file extension' do
15
- file.to_s.should == 'some/cache/path/to/file.index'
16
- end
17
- end
18
-
19
13
  describe 'backup_directory' do
20
14
  it "returns the cache path's backup path" do
21
15
  file.backup_directory.should == 'some/cache/path/to/backup'
22
16
  end
23
17
  end
24
18
 
19
+ describe 'to_s' do
20
+ it 'returns the cache path with the default file extension' do
21
+ file.to_s.should == 'Backend::File::Basic(some/cache/path/to/file.index)'
22
+ end
23
+ end
24
+
25
25
  end
@@ -2,25 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Backend::File::JSON do
4
4
 
5
- before(:each) do
6
- @file = described_class.new "some_cache_path"
7
- end
5
+ let(:file) { described_class.new 'some/cache/path/to/file' }
8
6
 
9
7
  describe "dump" do
10
8
  it "delegates to the given hash" do
11
9
  hash = stub :hash
12
10
 
13
- hash.should_receive(:dump_json).once.with "some_cache_path.json"
11
+ hash.should_receive(:dump_json).once.with "some/cache/path/to/file.json"
14
12
 
15
- @file.dump hash
13
+ file.dump hash
16
14
  end
17
15
  end
16
+
18
17
  describe "retrieve" do
19
18
  it "raises" do
20
19
  lambda do
21
- @file.retrieve
20
+ file.retrieve
22
21
  end.should raise_error("Can't retrieve from JSON file. Use text file.")
23
22
  end
24
23
  end
25
24
 
25
+ describe 'to_s' do
26
+ it 'returns the cache path with the default file extension' do
27
+ file.to_s.should == 'Backend::File::JSON(some/cache/path/to/file.json)'
28
+ end
29
+ end
30
+
26
31
  end
@@ -2,25 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Backend::File::Marshal do
4
4
 
5
- before(:each) do
6
- @file = described_class.new "some_cache_path"
7
- end
5
+ let(:file) { described_class.new 'some/cache/path/to/file' }
8
6
 
9
7
  describe "dump" do
10
8
  it "delegates to the given hash" do
11
9
  hash = stub :hash
12
10
 
13
- hash.should_receive(:dump_marshalled).once.with "some_cache_path.dump"
11
+ hash.should_receive(:dump_marshalled).once.with "some/cache/path/to/file.dump"
14
12
 
15
- @file.dump hash
13
+ file.dump hash
16
14
  end
17
15
  end
16
+
18
17
  describe "retrieve" do
19
18
  it "raises" do
20
19
  lambda do
21
- @file.retrieve
20
+ file.retrieve
22
21
  end.should raise_error("Can't retrieve from marshalled file. Use text file.")
23
22
  end
24
23
  end
25
24
 
25
+ describe 'to_s' do
26
+ it 'returns the cache path with the default file extension' do
27
+ file.to_s.should == 'Backend::File::Marshal(some/cache/path/to/file.dump)'
28
+ end
29
+ end
30
+
26
31
  end
@@ -10,7 +10,7 @@ describe Backend::Files do
10
10
 
11
11
  @prepared = @files.prepared
12
12
 
13
- @index = @files.index
13
+ @index = @files.inverted
14
14
  @weights = @files.weights
15
15
  @similarity = @files.similarity
16
16
  @configuration = @files.configuration
@@ -25,11 +25,14 @@ describe Backend::Files do
25
25
  end
26
26
 
27
27
  describe "dump indexes" do
28
+ before(:each) do
29
+ @files.stub! :timed_exclaim
30
+ end
28
31
  describe "dump_index" do
29
32
  it "uses the right file" do
30
33
  @index.should_receive(:dump).once.with :some_hash
31
34
 
32
- @files.dump_index :some_hash
35
+ @files.dump_inverted :some_hash
33
36
  end
34
37
  end
35
38
  describe "dump_weights" do
@@ -63,9 +66,9 @@ describe Backend::Files do
63
66
  it "uses the right file" do
64
67
  Yajl::Parser.stub! :parse
65
68
 
66
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_index.json', 'r'
69
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_inverted.json', 'r'
67
70
 
68
- @files.load_index
71
+ @files.load_inverted
69
72
  end
70
73
  end
71
74
  describe "load_weights" do
@@ -102,7 +105,7 @@ describe Backend::Files do
102
105
  it 'uses the right method' do
103
106
  @index.should_receive(:cache_ok?).once.with
104
107
 
105
- @files.index_cache_ok?
108
+ @files.inverted_cache_ok?
106
109
  end
107
110
  end
108
111
  describe "weights_cache_ok?" do
@@ -122,11 +125,11 @@ describe Backend::Files do
122
125
  end
123
126
 
124
127
  describe 'dump indexes' do
125
- describe 'index_cache_small?' do
128
+ describe 'inverted_cache_small?' do
126
129
  it 'uses the right method' do
127
130
  @index.should_receive(:cache_small?).once.with
128
131
 
129
- @files.index_cache_small?
132
+ @files.inverted_cache_small?
130
133
  end
131
134
  end
132
135
  describe 'weights_cache_small?' do
@@ -181,5 +184,16 @@ describe Backend::Files do
181
184
  @files.bundle_name.should == :some_name
182
185
  end
183
186
  end
187
+
188
+ describe 'to_s' do
189
+ it 'returns the right value' do
190
+ category = stub :category,
191
+ :identifier => "category_identifier",
192
+ :prepared_index_path => "prepared/index/path",
193
+ :index_path => 'index/path'
194
+
195
+ described_class.new("some_bundle", category).to_s.should == "Backend::Files(Backend::File::Text(prepared/index/path.txt), Backend::File::JSON(index/path.json), Backend::File::JSON(index/path.json), Backend::File::Marshal(index/path.dump), Backend::File::JSON(index/path.json))"
196
+ end
197
+ end
184
198
 
185
199
  end
@@ -64,4 +64,10 @@ describe Backend::Redis::Basic do
64
64
  end
65
65
  end
66
66
 
67
+ describe 'to_s' do
68
+ it 'returns the cache path with the default file extension' do
69
+ redis.to_s.should == 'Backend::Redis::Basic(some_namespace:*)'
70
+ end
71
+ end
72
+
67
73
  end
@@ -8,7 +8,7 @@ describe Backend::Redis::ListHash do
8
8
  it 'raises an error' do
9
9
  expect {
10
10
  index.member :some_sym
11
- }.to raise_error("Can't retrieve a single value from a Redis ListHash. Use Index::Redis::StringHash.")
11
+ }.to raise_error("Can't retrieve single value :some_sym from a Redis ListHash. Use Index::Redis::StringHash.")
12
12
  end
13
13
  end
14
14
 
@@ -17,7 +17,7 @@ describe Backend::Redis::ListHash do
17
17
  backend = stub :backend
18
18
  index.should_receive(:backend).and_return backend
19
19
 
20
- backend.stub! :lrange => :some_lrange_result
20
+ backend.stub! :zrange => :some_lrange_result
21
21
 
22
22
  index.collection(:anything).should == :some_lrange_result
23
23
  end
@@ -25,10 +25,16 @@ describe Backend::Redis::ListHash do
25
25
  backend = stub :backend
26
26
  index.should_receive(:backend).and_return backend
27
27
 
28
- backend.should_receive(:lrange).once.with "some_namespace:some_sym", 0, -1
28
+ backend.should_receive(:zrange).once.with "some_namespace:some_sym", 0, -1
29
29
 
30
30
  index.collection :some_sym
31
31
  end
32
32
  end
33
33
 
34
+ describe 'to_s' do
35
+ it 'returns the cache path with the default file extension' do
36
+ index.to_s.should == 'Backend::Redis::ListHash(some_namespace:*)'
37
+ end
38
+ end
39
+
34
40
  end
@@ -17,7 +17,7 @@ describe Backend::Redis::StringHash do
17
17
 
18
18
  describe 'collection' do
19
19
  it 'raises' do
20
- expect { index.collection :anything }.to raise_error("Can't retrieve a collection from a StringHash. Use Index::Redis::ListHash.")
20
+ expect { index.collection :anything }.to raise_error("Can't retrieve collection for :anything from a StringHash. Use Index::Redis::ListHash.")
21
21
  end
22
22
  end
23
23
 
@@ -38,4 +38,10 @@ describe Backend::Redis::StringHash do
38
38
  end
39
39
  end
40
40
 
41
+ describe 'to_s' do
42
+ it 'returns the cache path with the default file extension' do
43
+ index.to_s.should == 'Backend::Redis::StringHash(some_namespace:*)'
44
+ end
45
+ end
46
+
41
47
  end
@@ -58,18 +58,18 @@ describe Backend::Redis do
58
58
  end
59
59
  describe 'ids' do
60
60
  it 'delegates to the index' do
61
- index = stub :index
62
- redis.stub! :index => index
61
+ inverted = stub :inverted
62
+ redis.stub! :inverted => inverted
63
63
 
64
- index.should_receive(:collection).once.with :some_sym
64
+ inverted.should_receive(:collection).once.with :some_sym
65
65
 
66
66
  redis.ids :some_sym
67
67
  end
68
68
  it 'returns the value' do
69
- index = stub :index
70
- redis.stub! :index => index
69
+ inverted = stub :inverted
70
+ redis.stub! :inverted => inverted
71
71
 
72
- index.should_receive(:collection).any_number_of_times.and_return [1,2,3]
72
+ inverted.should_receive(:collection).any_number_of_times.and_return [1,2,3]
73
73
 
74
74
  redis.ids(:any).should == [1,2,3]
75
75
  end
@@ -132,22 +132,32 @@ describe Backend::Redis do
132
132
  end
133
133
  describe 'ids' do
134
134
  it 'delegates to the index' do
135
- index = stub :index
136
- redis.stub! :index => index
135
+ inverted = stub :inverted
136
+ redis.stub! :inverted => inverted
137
137
 
138
- index.should_receive(:collection).once.with :some_sym
138
+ inverted.should_receive(:collection).once.with :some_sym
139
139
 
140
140
  redis.ids :some_sym
141
141
  end
142
142
  it 'returns the value' do
143
- index = stub :index
144
- redis.stub! :index => index
143
+ inverted = stub :inverted
144
+ redis.stub! :inverted => inverted
145
145
 
146
- index.should_receive(:collection).any_number_of_times.and_return [1,2,3]
146
+ inverted.should_receive(:collection).any_number_of_times.and_return [1,2,3]
147
147
 
148
148
  redis.ids(:any).should == [1,2,3]
149
149
  end
150
150
  end
151
151
  end
152
+
153
+ describe 'to_s' do
154
+ it 'returns the right value' do
155
+ category = stub :category,
156
+ :identifier => "category_identifier",
157
+ :prepared_index_path => "prepared/index/path"
158
+
159
+ described_class.new("some_bundle", category).to_s.should == "Backend::Redis(Backend::File::Text(prepared/index/path.txt), some_bundle, category_identifier)"
160
+ end
161
+ end
152
162
 
153
163
  end
@@ -39,7 +39,7 @@ describe Categories do
39
39
  end
40
40
  end
41
41
 
42
- describe 'clear' do
42
+ describe 'clear_categories' do
43
43
  before(:each) do
44
44
  @categories = described_class.new
45
45
  end
@@ -56,7 +56,7 @@ describe Categories do
56
56
  it "is clear again after clearing" do
57
57
  @categories << stub(:category, :name => :some_name)
58
58
 
59
- @categories.clear
59
+ @categories.clear_categories
60
60
 
61
61
  @categories.categories.should be_empty
62
62
  @categories.category_hash.should be_empty
@@ -12,36 +12,36 @@ describe Category do
12
12
  let(:exact) { category.indexing_exact }
13
13
  let(:partial) { category.indexing_partial }
14
14
 
15
- describe 'backup_caches' do
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
- category.backup_caches
20
+ category.backup
21
21
  end
22
22
  end
23
- describe 'restore_caches' do
23
+ describe 'restore' 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
- category.restore_caches
28
+ category.restore
29
29
  end
30
30
  end
31
- describe 'check_caches' do
31
+ describe 'check' 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
- category.check_caches
36
+ category.check
37
37
  end
38
38
  end
39
- describe 'clear_caches' do
39
+ describe 'clear' 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
- category.clear_caches
44
+ category.clear
45
45
  end
46
46
  end
47
47
 
@@ -79,7 +79,7 @@ describe Category do
79
79
  end
80
80
  it 'should use the exact index to generate the partial index' do
81
81
  exact_index = stub :exact_index
82
- exact.stub! :index => exact_index
82
+ exact.stub! :inverted => exact_index
83
83
  partial.should_receive(:generate_partial_from).once.with(exact_index)
84
84
 
85
85
  category.generate_partial
@@ -94,7 +94,7 @@ describe Category do
94
94
  end
95
95
  end
96
96
 
97
- describe 'generate_caches' do
97
+ describe 'cache' do
98
98
  it 'should call multiple methods in order' do
99
99
  category.should_receive(:configure).once.with().ordered
100
100
  category.should_receive(:generate_caches_from_source).once.with().ordered
@@ -103,7 +103,7 @@ describe Category do
103
103
  category.should_receive(:dump_caches).once.with().ordered
104
104
  category.should_receive(:timed_exclaim).once.ordered
105
105
 
106
- category.generate_caches
106
+ category.cache
107
107
  end
108
108
  end
109
109
 
@@ -159,34 +159,13 @@ describe Category do
159
159
  end
160
160
  end
161
161
 
162
- describe "cache" do
163
- before(:each) do
164
- category.stub! :generate_caches
165
- category.stub! :configure
166
- end
167
- it "prepares the cache directory" do
168
- category.should_receive(:prepare_index_directory).once.with
169
-
170
- category.cache
171
- end
172
- it "tells the indexer to index" do
173
- category.should_receive(:generate_caches).once.with
174
-
175
- category.cache
176
- end
177
- end
178
162
  describe "index" do
179
163
  before(:each) do
180
164
  @indexer = stub :indexer, :index => nil
181
165
  category.stub! :indexer => @indexer
182
166
  end
183
- it "prepares the cache directory" do
184
- category.should_receive(:prepare_index_directory).once.with
185
-
186
- category.prepare
187
- end
188
167
  it "tells the indexer to index" do
189
- @indexer.should_receive(:index).once.with
168
+ @indexer.should_receive(:index).once.with [category]
190
169
 
191
170
  category.prepare
192
171
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Category do
4
+
5
+ let(:index) { Index::Memory.new :some_index, source: [] }
6
+ let(:category) { described_class.new :some_category, index }
7
+
8
+ it 'should set defaults correctly' do
9
+ category.indexing_exact.weights_strategy.should == Generators::Weights::Default
10
+ category.indexing_exact.partial_strategy.should be_kind_of(Generators::Partial::None)
11
+ category.indexing_exact.similarity_strategy.should == Generators::Similarity::Default
12
+
13
+ category.indexing_partial.weights_strategy.should be_kind_of(Generators::Weights::Logarithmic)
14
+ category.indexing_partial.partial_strategy.should == Generators::Partial::Default
15
+ category.indexing_partial.similarity_strategy.should be_kind_of(Generators::Similarity::None)
16
+
17
+ category.indexed_exact.similarity_strategy.should == Generators::Similarity::Default
18
+
19
+ category.indexed_partial.similarity_strategy.should be_kind_of(Generators::Similarity::None)
20
+ end
21
+
22
+ end
@@ -2,6 +2,36 @@ require 'spec_helper'
2
2
 
3
3
  describe Index::Base do
4
4
 
5
+ context 'in general' do
6
+ context 'with #each source' do
7
+ let(:index) { described_class.new :some_name, source: [] }
8
+
9
+ it 'does things in order' do
10
+ index.should_receive(:check_source_empty).once.with.ordered
11
+ index.should_receive(:index_in_parallel).once.with.ordered
12
+
13
+ index.index
14
+ end
15
+ end
16
+ context 'with non#each source' do
17
+ let(:source) { stub :source, :harvest => nil }
18
+ let(:index) { described_class.new :some_name, source: source }
19
+
20
+ it 'does things in order' do
21
+ category = stub :category
22
+ index.stub! :categories => [
23
+ category,
24
+ category,
25
+ category
26
+ ]
27
+
28
+ category.should_receive(:index).exactly(3).times
29
+
30
+ index.index
31
+ end
32
+ end
33
+ end
34
+
5
35
  context "with categories" do
6
36
  before(:each) do
7
37
  @source = []
@@ -12,28 +12,21 @@ describe Indexed::Bundle::Memory do
12
12
 
13
13
  describe 'to_s' do
14
14
  it 'does something' do
15
- @bundle.to_s.should == <<-TO_S
16
- Memory
17
- Files:
18
- Index: spec/test_directory/index/test/some_index/some_category_some_name_index.json
19
- Weights: spec/test_directory/index/test/some_index/some_category_some_name_weights.json
20
- Similarity: spec/test_directory/index/test/some_index/some_category_some_name_similarity.dump
21
- Config: spec/test_directory/index/test/some_index/some_category_some_name_configuration.json
22
- TO_S
15
+ @bundle.to_s.should == "Indexed::Bundle::Memory(test:some_index:some_category:some_name, Backend::Files(Backend::File::Text(spec/test_directory/index/test/some_index/prepared_some_category_index.txt), Backend::File::JSON(spec/test_directory/index/test/some_index/some_category_some_name_inverted.json), Backend::File::JSON(spec/test_directory/index/test/some_index/some_category_some_name_weights.json), Backend::File::Marshal(spec/test_directory/index/test/some_index/some_category_some_name_similarity.dump), Backend::File::JSON(spec/test_directory/index/test/some_index/some_category_some_name_configuration.json)))"
23
16
  end
24
17
  end
25
18
 
26
19
  describe 'clear_index' do
27
20
  before(:each) do
28
- @bundle.instance_variable_set(:@index, :not_empty)
21
+ @bundle.instance_variable_set(:@inverted, :not_empty)
29
22
  end
30
- it 'has not cleared the index' do
31
- @bundle.index.should == :not_empty
23
+ it 'has not cleared the inverted index' do
24
+ @bundle.inverted.should == :not_empty
32
25
  end
33
- it 'clears the index' do
34
- @bundle.clear_index
26
+ it 'clears the inverted index' do
27
+ @bundle.clear_inverted
35
28
 
36
- @bundle.index.should be_empty
29
+ @bundle.inverted.should be_empty
37
30
  end
38
31
  end
39
32
  describe 'clear_weights' do
@@ -78,13 +71,13 @@ Memory
78
71
 
79
72
  describe 'identifier' do
80
73
  it 'should return a specific identifier' do
81
- @bundle.identifier.should == 'some_index:some_category:some_name'
74
+ @bundle.identifier.should == 'test:some_index:some_category:some_name'
82
75
  end
83
76
  end
84
77
 
85
78
  describe 'ids' do
86
79
  before(:each) do
87
- @bundle.instance_variable_set :@index, { :existing => :some_ids }
80
+ @bundle.instance_variable_set :@inverted, { :existing => :some_ids }
88
81
  end
89
82
  it 'should return an empty array if not found' do
90
83
  @bundle.ids(:non_existing).should == []
@@ -108,7 +101,7 @@ Memory
108
101
 
109
102
  describe 'load' do
110
103
  it 'should trigger loads' do
111
- @bundle.should_receive(:load_index).once.with
104
+ @bundle.should_receive(:load_inverted).once.with
112
105
  @bundle.should_receive(:load_weights).once.with
113
106
  @bundle.should_receive(:load_similarity).once.with
114
107
  @bundle.should_receive(:load_configuration).once.with
@@ -124,9 +117,9 @@ Memory
124
117
  it "uses the right file" do
125
118
  Yajl::Parser.stub! :parse
126
119
 
127
- File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_index.json', 'r'
120
+ File.should_receive(:open).once.with 'spec/test_directory/index/test/some_index/some_category_some_name_inverted.json', 'r'
128
121
 
129
- @bundle.load_index
122
+ @bundle.load_inverted
130
123
  end
131
124
  end
132
125
  describe "load_weights" do
@@ -166,7 +159,7 @@ Memory
166
159
  @bundle = described_class.new :some_name, @category, :similarity
167
160
  end
168
161
  it 'should initialize the index correctly' do
169
- @bundle.index.should == {}
162
+ @bundle.inverted.should == {}
170
163
  end
171
164
  it 'should initialize the weights index correctly' do
172
165
  @bundle.weights.should == {}