picky 0.11.2 → 0.12.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 (81) hide show
  1. data/lib/picky/Index_api.rb +49 -0
  2. data/lib/picky/alias_instances.rb +4 -1
  3. data/lib/picky/application.rb +16 -15
  4. data/lib/picky/cacher/partial/{subtoken.rb → substring.rb} +19 -18
  5. data/lib/picky/{character_substitution/european.rb → character_substituters/west_european.rb} +2 -2
  6. data/lib/picky/configuration/index.rb +67 -0
  7. data/lib/picky/cores.rb +3 -0
  8. data/lib/picky/index/bundle.rb +35 -51
  9. data/lib/picky/index/file/basic.rb +39 -5
  10. data/lib/picky/index/file/json.rb +10 -0
  11. data/lib/picky/index/file/marshal.rb +10 -0
  12. data/lib/picky/index/file/text.rb +22 -0
  13. data/lib/picky/index/files.rb +11 -36
  14. data/lib/picky/indexed/bundle.rb +61 -0
  15. data/lib/picky/{index → indexed}/categories.rb +1 -1
  16. data/lib/picky/{index → indexed}/category.rb +13 -16
  17. data/lib/picky/{index/type.rb → indexed/index.rb} +6 -6
  18. data/lib/picky/{index/types.rb → indexed/indexes.rb} +10 -10
  19. data/lib/picky/{index → indexed}/wrappers/exact_first.rb +8 -8
  20. data/lib/picky/indexers/no_source_specified_error.rb +1 -1
  21. data/lib/picky/indexers/serial.rb +64 -0
  22. data/lib/picky/indexers/solr.rb +1 -3
  23. data/lib/picky/indexes_api.rb +41 -0
  24. data/lib/picky/indexing/bundle.rb +43 -13
  25. data/lib/picky/indexing/category.rb +17 -64
  26. data/lib/picky/indexing/{type.rb → index.rb} +13 -3
  27. data/lib/picky/indexing/{types.rb → indexes.rb} +22 -22
  28. data/lib/picky/loader.rb +17 -22
  29. data/lib/picky/query/base.rb +1 -1
  30. data/lib/picky/rack/harakiri.rb +9 -2
  31. data/lib/picky/signals.rb +1 -1
  32. data/lib/picky/sources/base.rb +14 -14
  33. data/lib/picky/sources/couch.rb +8 -7
  34. data/lib/picky/sources/csv.rb +10 -10
  35. data/lib/picky/sources/db.rb +8 -8
  36. data/lib/picky/sources/delicious.rb +2 -2
  37. data/lib/picky/sources/wrappers/location.rb +3 -3
  38. data/lib/picky/tokenizers/base.rb +1 -11
  39. data/lib/picky/tokenizers/index.rb +0 -1
  40. data/lib/picky/tokenizers/query.rb +0 -1
  41. data/lib/tasks/index.rake +4 -4
  42. data/lib/tasks/shortcuts.rake +4 -4
  43. data/lib/tasks/try.rake +8 -8
  44. data/project_prototype/Gemfile +1 -1
  45. data/project_prototype/app/application.rb +13 -12
  46. data/spec/lib/application_spec.rb +10 -38
  47. data/spec/lib/cacher/partial/{subtoken_spec.rb → substring_spec.rb} +0 -0
  48. data/spec/lib/{character_substitution/european_spec.rb → character_substituters/west_european_spec.rb} +6 -2
  49. data/spec/lib/configuration/index_spec.rb +80 -0
  50. data/spec/lib/cores_spec.rb +1 -1
  51. data/spec/lib/index/file/text_spec.rb +1 -1
  52. data/spec/lib/index/files_spec.rb +12 -32
  53. data/spec/lib/indexed/bundle_spec.rb +119 -0
  54. data/spec/lib/{indexing → indexed}/categories_spec.rb +13 -14
  55. data/spec/lib/{index → indexed}/category_spec.rb +6 -6
  56. data/spec/lib/{index/type_spec.rb → indexed/index_spec.rb} +3 -3
  57. data/spec/lib/{index → indexed}/wrappers/exact_first_spec.rb +5 -5
  58. data/spec/lib/indexers/serial_spec.rb +62 -0
  59. data/spec/lib/indexing/bundle_partial_generation_speed_spec.rb +7 -5
  60. data/spec/lib/indexing/bundle_spec.rb +9 -14
  61. data/spec/lib/indexing/category_spec.rb +9 -125
  62. data/spec/lib/indexing/{type_spec.rb → index_spec.rb} +3 -3
  63. data/spec/lib/query/base_spec.rb +1 -1
  64. data/spec/lib/query/full_spec.rb +1 -1
  65. data/spec/lib/query/live_spec.rb +2 -4
  66. data/spec/lib/sources/couch_spec.rb +5 -5
  67. data/spec/lib/sources/db_spec.rb +6 -7
  68. data/spec/lib/tokenizers/base_spec.rb +1 -24
  69. data/spec/lib/tokenizers/query_spec.rb +0 -1
  70. metadata +38 -41
  71. data/lib/picky/bundle.rb +0 -33
  72. data/lib/picky/configuration/indexes.rb +0 -51
  73. data/lib/picky/configuration/queries.rb +0 -15
  74. data/lib/picky/indexers/base.rb +0 -85
  75. data/lib/picky/indexers/default.rb +0 -3
  76. data/lib/picky/type.rb +0 -46
  77. data/lib/picky/types.rb +0 -41
  78. data/lib/tasks/cache.rake +0 -46
  79. data/spec/lib/configuration/indexes_spec.rb +0 -28
  80. data/spec/lib/index/bundle_spec.rb +0 -151
  81. data/spec/lib/indexers/base_spec.rb +0 -89
@@ -9,7 +9,7 @@ describe Application do
9
9
  lambda {
10
10
  class MinimalTestApplication < Application
11
11
  books = index :books, Sources::DB.new('SELECT id, title FROM books', :file => 'app/db.yml')
12
- books.category :title
12
+ books.define_category :title
13
13
 
14
14
 
15
15
  full = Query::Full.new books
@@ -28,7 +28,6 @@ describe Application do
28
28
  #
29
29
  class TestApplication < Application
30
30
  default_indexing removes_characters: /[^a-zA-Z0-9\s\/\-\"\&\.]/,
31
- contracts_expressions: [/mr\.\s*|mister\s*/i, 'mr '],
32
31
  stopwords: /\b(and|the|of|it|in|for)\b/,
33
32
  splits_text_on: /[\s\/\-\"\&\.]/,
34
33
  removes_characters_after_splitting: /[\.]/
@@ -38,13 +37,16 @@ describe Application do
38
37
  splits_text_on: /[\s\/\-\,\&]+/,
39
38
  normalizes_words: [[/Deoxyribonucleic Acid/i, 'DNA']],
40
39
 
41
- substitutes_characters_with: CharacterSubstitution::European.new,
42
- maximum_tokens: 5
40
+ substitutes_characters_with: CharacterSubstituters::WestEuropean.new,
41
+ maximum_tokens: 5
43
42
 
44
- books_index = index :books, Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
45
- books_index.category :title, similarity: Similarity::DoubleLevenshtone.new(3) # Up to three similar title word indexed.
46
- books_index.category :author
47
- books_index.category :isbn, partial: Partial::None.new # Partially searching on an ISBN makes not much sense.
43
+ books_index = index :books,
44
+ Sources::DB.new('SELECT id, title, author, isbn13 as isbn FROM books', :file => 'app/db.yml')
45
+ books_index.define_category :title,
46
+ similarity: Similarity::DoubleLevenshtone.new(3) # Up to three similar title word indexed.
47
+ books_index.define_category :author
48
+ books_index.define_category :isbn,
49
+ partial: Partial::None.new # Partially searching on an ISBN makes not much sense.
48
50
 
49
51
  full = Query::Full.new books_index
50
52
  live = Query::Live.new books_index
@@ -88,34 +90,4 @@ describe Application do
88
90
  end
89
91
  end
90
92
 
91
- describe "indexes" do
92
-
93
- end
94
- describe "indexing" do
95
- it 'should be there' do
96
- lambda { Application.indexing }.should_not raise_error
97
- end
98
- it "should return a new Routing instance" do
99
- Application.indexing.should be_kind_of(Configuration::Indexes)
100
- end
101
- it "should cache the instance" do
102
- Application.indexing.should == Application.indexing
103
- end
104
- end
105
-
106
- describe "queries" do
107
-
108
- end
109
- describe "querying" do
110
- it 'should be there' do
111
- lambda { Application.querying }.should_not raise_error
112
- end
113
- it "should return a new Routing instance" do
114
- Application.querying.should be_kind_of(Configuration::Queries)
115
- end
116
- it "should cache the instance" do
117
- Application.querying.should == Application.querying
118
- end
119
- end
120
-
121
93
  end
@@ -2,9 +2,9 @@
2
2
  #
3
3
  require 'spec_helper'
4
4
 
5
- describe CharacterSubstitution do
5
+ describe CharacterSubstituters do
6
6
  before(:each) do
7
- @substituter = CharacterSubstitution::European.new
7
+ @substituter = CharacterSubstituters::WestEuropean.new
8
8
  end
9
9
 
10
10
  # A bit of metaprogramming to help with the myriads of its.
@@ -93,6 +93,10 @@ describe CharacterSubstitution do
93
93
  result = performance_of { @substituter.substitute('ä') }
94
94
  result.should < 0.00009
95
95
  end
96
+ it "is fast" do
97
+ result = performance_of { @substituter.substitute('abcdefghijklmnopqrstuvwxyz1234567890') }
98
+ result.should < 0.00015
99
+ end
96
100
  end
97
101
 
98
102
  end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Configuration::Index' do
4
+
5
+ before(:each) do
6
+ @index = stub :index, :name => :some_index
7
+ @category = stub :category, :name => :some_category
8
+ @config = Configuration::Index.new @index, @category
9
+ end
10
+
11
+ describe "index_name" do
12
+ it "returns the right thing" do
13
+ @config.index_name.should == :some_index
14
+ end
15
+ end
16
+ describe "category_name" do
17
+ it "returns the right thing" do
18
+ @config.category_name.should == :some_category
19
+ end
20
+ end
21
+
22
+ describe "index_path" do
23
+ it "caches" do
24
+ @config.index_path(:some_bundle, :some_name).should_not equal(@config.index_path(:some_bundle, :some_name))
25
+ end
26
+ it "returns the right thing" do
27
+ @config.index_path(:some_bundle, :some_name).should == 'some/search/root/index/test/some_index/some_category_some_bundle_some_name'
28
+ end
29
+ end
30
+
31
+ # describe "file_name" do
32
+ # it "caches" do
33
+ # @config.file_name.should equal(@config.file_name)
34
+ # end
35
+ # it "returns the right thing" do
36
+ # @config.file_name.should == 'some_index_some_category'
37
+ # end
38
+ # end
39
+
40
+ describe "identifier" do
41
+ it "caches" do
42
+ @config.identifier.should equal(@config.identifier)
43
+ end
44
+ it "returns the right thing" do
45
+ @config.identifier.should == 'some_index some_category'
46
+ end
47
+ end
48
+ describe "index_root" do
49
+ it "caches" do
50
+ @config.index_root.should equal(@config.index_root)
51
+ end
52
+ it "returns the right thing" do
53
+ @config.index_root.should == 'some/search/root/index'
54
+ end
55
+ end
56
+ describe "index_directory" do
57
+ it "caches" do
58
+ @config.index_directory.should equal(@config.index_directory)
59
+ end
60
+ it "returns the right thing" do
61
+ @config.index_directory.should == 'some/search/root/index/test/some_index'
62
+ end
63
+ end
64
+ describe "prepared_index_path" do
65
+ it "caches" do
66
+ @config.prepared_index_path.should equal(@config.prepared_index_path)
67
+ end
68
+ it "returns the right thing" do
69
+ @config.prepared_index_path.should == 'some/search/root/index/test/some_index/prepared_some_category_index'
70
+ end
71
+ end
72
+ describe "prepare_index_directory" do
73
+ it "calls the right thing" do
74
+ FileUtils.should_receive(:mkdir_p).once.with 'some/search/root/index/test/some_index'
75
+
76
+ @config.prepare_index_directory
77
+ end
78
+ end
79
+
80
+ end
@@ -26,7 +26,7 @@ describe Cores do
26
26
  it "fails" do
27
27
  lambda {
28
28
  Cores.forked [1, 2]
29
- }.should raise_error(LocalJumpError)
29
+ }.should raise_error("Block argument needed when running Cores.forked")
30
30
  end
31
31
  end
32
32
  end
@@ -24,7 +24,7 @@ describe Index::File::Text do
24
24
  before(:each) do
25
25
  @io = stub :io
26
26
  @io.should_receive(:each_line).once.with.and_yield '123456,some_nice_token'
27
- File.should_receive(:open).any_number_of_times.and_yield @io
27
+ ::File.should_receive(:open).any_number_of_times.and_yield @io
28
28
  end
29
29
  it "yields split lines and returns the id and token text" do
30
30
  @file.retrieve do |id, token|
@@ -3,28 +3,17 @@ require 'spec_helper'
3
3
  describe Index::Files do
4
4
 
5
5
  before(:each) do
6
- @files_class = Index::Files
7
- @files = @files_class.new :some_name, :some_category, :some_type
6
+ @index = stub :index, :name => :some_index
7
+ @category = stub :category, :name => :some_category
8
+ @configuration = Configuration::Index.new @index, @category
8
9
 
9
- @prepared = @files.prepared
10
+ @files = Index::Files.new :some_name, @configuration
10
11
 
11
- @index = @files.index
12
- @similarity = @files.similarity
13
- @weights = @files.weights
14
- end
15
-
16
- describe 'create_directory' do
17
- it 'should use makedirs to create the necessary directory structure' do
18
- FileUtils.should_receive(:mkdir_p).once.with 'some/search/root/index/test/some_type'
19
-
20
- @files.create_directory
21
- end
22
- end
23
-
24
- describe 'cache_directory' do
25
- it 'should be correct' do
26
- @files.cache_directory.should == 'some/search/root/index/test/some_type'
27
- end
12
+ @prepared = @files.prepared
13
+
14
+ @index = @files.index
15
+ @similarity = @files.similarity
16
+ @weights = @files.weights
28
17
  end
29
18
 
30
19
  describe "retrieve" do
@@ -67,7 +56,7 @@ describe Index::Files do
67
56
  it "uses the right file" do
68
57
  Yajl::Parser.stub! :parse
69
58
 
70
- File.should_receive(:open).once.with 'some/search/root/index/test/some_type/some_name_some_category_index.json', 'r'
59
+ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_index.json', 'r'
71
60
 
72
61
  @files.load_index
73
62
  end
@@ -76,7 +65,7 @@ describe Index::Files do
76
65
  it "uses the right file" do
77
66
  Marshal.stub! :load
78
67
 
79
- File.should_receive(:open).once.with 'some/search/root/index/test/some_type/some_name_some_category_similarity.dump', 'r:binary'
68
+ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_similarity.dump', 'r:binary'
80
69
 
81
70
  @files.load_similarity
82
71
  end
@@ -85,7 +74,7 @@ describe Index::Files do
85
74
  it "uses the right file" do
86
75
  Yajl::Parser.stub! :parse
87
76
 
88
- File.should_receive(:open).once.with 'some/search/root/index/test/some_type/some_name_some_category_weights.json', 'r'
77
+ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_weights.json', 'r'
89
78
 
90
79
  @files.load_weights
91
80
  end
@@ -169,18 +158,9 @@ describe Index::Files do
169
158
  end
170
159
 
171
160
  describe 'initialization' do
172
- before(:each) do
173
- @files = @files_class.new :some_name, :some_category, :some_type
174
- end
175
161
  it 'should initialize the name correctly' do
176
162
  @files.bundle_name.should == :some_name
177
163
  end
178
- it 'should initialize the name correctly' do
179
- @files.category_name.should == :some_category
180
- end
181
- it 'should initialize the name correctly' do
182
- @files.type_name.should == :some_type
183
- end
184
164
  end
185
165
 
186
166
  end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe Indexed::Bundle do
4
+
5
+ before(:each) do
6
+ @category = stub :category, :name => :some_category
7
+ @index = stub :index, :name => :some_index
8
+ @configuration = Configuration::Index.new @index, @category
9
+
10
+ @similarity = stub :similarity
11
+ @bundle_class = Indexed::Bundle
12
+ @bundle = @bundle_class.new :some_name, @configuration, @similarity
13
+ end
14
+
15
+ describe 'identifier' do
16
+ it 'should return a specific identifier' do
17
+ @bundle.identifier.should == 'some_index some_category (some_name)'
18
+ end
19
+ end
20
+
21
+ describe 'load_from_index_file' do
22
+ it 'should call two methods in order' do
23
+ @bundle.should_receive(:load_from_index_generation_message).once.ordered
24
+ @bundle.should_receive(:clear).once.ordered
25
+ @bundle.should_receive(:retrieve).once.ordered
26
+
27
+ @bundle.load_from_index_file
28
+ end
29
+ end
30
+
31
+ describe 'ids' do
32
+ before(:each) do
33
+ @bundle.instance_variable_set :@index, { :existing => :some_ids }
34
+ end
35
+ it 'should return an empty array if not found' do
36
+ @bundle.ids(:non_existing).should == []
37
+ end
38
+ it 'should return the ids if found' do
39
+ @bundle.ids(:existing).should == :some_ids
40
+ end
41
+ end
42
+
43
+ describe 'weight' do
44
+ before(:each) do
45
+ @bundle.instance_variable_set :@weights, { :existing => :specific }
46
+ end
47
+ it 'should return nil' do
48
+ @bundle.weight(:non_existing).should == nil
49
+ end
50
+ it 'should return the weight for the text' do
51
+ @bundle.weight(:existing).should == :specific
52
+ end
53
+ end
54
+
55
+ describe 'load' do
56
+ it 'should trigger loads' do
57
+ @bundle.should_receive(:load_index).once.with
58
+ @bundle.should_receive(:load_similarity).once.with
59
+ @bundle.should_receive(:load_weights).once.with
60
+
61
+ @bundle.load
62
+ end
63
+ end
64
+ describe "loading indexes" do
65
+ before(:each) do
66
+ @bundle.stub! :timed_exclaim
67
+ end
68
+ describe "load_index" do
69
+ it "uses the right file" do
70
+ Yajl::Parser.stub! :parse
71
+
72
+ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_index.json', 'r'
73
+
74
+ @bundle.load_index
75
+ end
76
+ end
77
+ describe "load_similarity" do
78
+ it "uses the right file" do
79
+ Marshal.stub! :load
80
+
81
+ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_similarity.dump', 'r:binary'
82
+
83
+ @bundle.load_similarity
84
+ end
85
+ end
86
+ describe "load_weights" do
87
+ it "uses the right file" do
88
+ Yajl::Parser.stub! :parse
89
+
90
+ File.should_receive(:open).once.with 'some/search/root/index/test/some_index/some_category_some_name_weights.json', 'r'
91
+
92
+ @bundle.load_weights
93
+ end
94
+ end
95
+ end
96
+
97
+ describe 'initialization' do
98
+ before(:each) do
99
+ @category = stub :category, :name => :some_category
100
+ @index = stub :index, :name => :some_index
101
+ @configuration = Configuration::Index.new @index, @category
102
+
103
+ @bundle = @bundle_class.new :some_name, @configuration, :similarity
104
+ end
105
+ it 'should initialize the index correctly' do
106
+ @bundle.index.should == {}
107
+ end
108
+ it 'should initialize the weights index correctly' do
109
+ @bundle.weights.should == {}
110
+ end
111
+ it 'should initialize the similarity index correctly' do
112
+ @bundle.similarity.should == {}
113
+ end
114
+ it 'should initialize the similarity strategy correctly' do
115
+ @bundle.similarity_strategy.should == :similarity
116
+ end
117
+ end
118
+
119
+ end
@@ -1,11 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Index::Categories do
4
-
3
+ describe Indexed::Categories do
5
4
  context 'with option ignore_unassigned_tokens' do
6
5
  context 'ignore_unassigned_tokens true' do
7
6
  before(:each) do
8
- @categories = Index::Categories.new ignore_unassigned_tokens: true
7
+ @categories = Indexed::Categories.new ignore_unassigned_tokens: true
9
8
  end
10
9
  it 'should return the right value' do
11
10
  @categories.ignore_unassigned_tokens.should == true
@@ -13,7 +12,7 @@ describe Index::Categories do
13
12
  end
14
13
  context 'ignore_unassigned_tokens false' do
15
14
  before(:each) do
16
- @categories = Index::Categories.new ignore_unassigned_tokens: false
15
+ @categories = Indexed::Categories.new ignore_unassigned_tokens: false
17
16
  end
18
17
  it 'should return the right value' do
19
18
  @categories.ignore_unassigned_tokens.should == false
@@ -23,12 +22,12 @@ describe Index::Categories do
23
22
 
24
23
  context "with real categories" do
25
24
  before(:each) do
26
- @type1 = stub :type1, :name => :some_type
25
+ @index1 = stub :index1, :name => :some_index
27
26
 
28
- @categories = Index::Categories.new
29
- @categories << Index::Category.new(:category1, @type1)
30
- @categories << Index::Category.new(:category2, @type1)
31
- @categories << Index::Category.new(:category3, @type1)
27
+ @categories = Indexed::Categories.new
28
+ @categories << Indexed::Category.new(:category1, @index1)
29
+ @categories << Indexed::Category.new(:category2, @index1)
30
+ @categories << Indexed::Category.new(:category3, @index1)
32
31
  end
33
32
  describe "similar_possible_for" do
34
33
  before(:each) do
@@ -42,13 +41,13 @@ describe Index::Categories do
42
41
 
43
42
  context 'without options' do
44
43
  before(:each) do
45
- @type1 = stub :type1, :name => :some_type
44
+ @index1 = stub :index1, :name => :some_index
46
45
 
47
- @category1 = Index::Category.new :category1, @type1
48
- @category2 = Index::Category.new :category2, @type1
49
- @category3 = Index::Category.new :category3, @type1
46
+ @category1 = Indexed::Category.new :category1, @index1
47
+ @category2 = Indexed::Category.new :category2, @index1
48
+ @category3 = Indexed::Category.new :category3, @index1
50
49
 
51
- @categories = Index::Categories.new
50
+ @categories = Indexed::Categories.new
52
51
  @categories << @category1
53
52
  @categories << @category2
54
53
  @categories << @category3
@@ -1,16 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Index::Category do
3
+ describe Indexed::Category do
4
4
 
5
5
  before(:each) do
6
- @type = stub :type, :name => :some_type
6
+ @index = stub :index, :name => :some_index
7
7
  @partial = stub :partial
8
8
  @weights = stub :weights
9
9
  @similarity = stub :similarity
10
- @category = Index::Category.new :some_name, @type, :partial => @partial,
11
- :weights => @weights,
12
- :similarity => @similarity,
13
- :qualifiers => [:q, :qualifier]
10
+ @category = Indexed::Category.new :some_name, @index, :partial => @partial,
11
+ :weights => @weights,
12
+ :similarity => @similarity,
13
+ :qualifiers => [:q, :qualifier]
14
14
 
15
15
  @exact = stub :exact, :dump => nil
16
16
  @category.stub! :exact => @exact
@@ -1,12 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Index::Type do
3
+ describe Indexed::Index do
4
4
 
5
5
  context "with categories" do
6
6
  before(:each) do
7
7
  @categories = stub :categories
8
8
 
9
- @index = Index::Type.new :some_name
9
+ @index = Indexed::Index.new :some_name
10
10
  @index.add_category :some_category_name1
11
11
  @index.add_category :some_category_name2
12
12
 
@@ -31,7 +31,7 @@ describe Index::Type do
31
31
 
32
32
  context "no categories" do
33
33
  it "works" do
34
- Index::Type.new :some_name
34
+ Indexed::Index.new :some_name
35
35
  end
36
36
  end
37
37
 
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Index::Wrappers::ExactFirst do
3
+ describe Indexed::Wrappers::ExactFirst do
4
4
 
5
5
  before(:each) do
6
6
  @exact = stub :exact
7
7
  @partial = stub :partial
8
8
  @category = stub :category, :exact => @exact, :partial => @partial
9
9
 
10
- @wrapper = Index::Wrappers::ExactFirst.new @category
10
+ @wrapper = Indexed::Wrappers::ExactFirst.new @category
11
11
  end
12
12
 
13
13
  describe "self.wrap" do
@@ -23,17 +23,17 @@ describe Index::Wrappers::ExactFirst do
23
23
  # type.categories.should be_kind_of(Index::Wrappers::ExactFirst)
24
24
  # end
25
25
  it "returns the type" do
26
- type = Index::Type.new :type_name
26
+ type = Indexed::Index.new :type_name
27
27
  type.add_category :some_category
28
28
 
29
- Index::Wrappers::ExactFirst.wrap(type).should == type
29
+ Indexed::Wrappers::ExactFirst.wrap(type).should == type
30
30
  end
31
31
  end
32
32
  context "category" do
33
33
  it "wraps each category" do
34
34
  category = stub :category, :exact => :exact, :partial => :partial
35
35
 
36
- Index::Wrappers::ExactFirst.wrap(category).should be_kind_of(Index::Wrappers::ExactFirst)
36
+ Indexed::Wrappers::ExactFirst.wrap(category).should be_kind_of(Indexed::Wrappers::ExactFirst)
37
37
  end
38
38
  end
39
39
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe Indexers::Serial do
4
+
5
+ before(:each) do
6
+ @index = stub :index, :name => :some_index
7
+ @category = stub :category, :name => :some_category
8
+ @configuration = Configuration::Index.new @index, @category
9
+
10
+ @source = stub :source
11
+ @tokenizer = stub :tokenizer
12
+ @indexer = Indexers::Serial.new @configuration, @source, @tokenizer
13
+ @indexer.stub! :timed_exclaim
14
+ end
15
+
16
+ describe "tokenizer" do
17
+ it "returns the right one" do
18
+ @indexer.tokenizer.should == @tokenizer
19
+ end
20
+ end
21
+
22
+ describe "indexing_message" do
23
+ it "informs the user about what it is going to index" do
24
+ @indexer.should_receive(:timed_exclaim).once.with 'INDEX some_index some_category'
25
+
26
+ @indexer.indexing_message
27
+ end
28
+ end
29
+
30
+ describe "tokenizer" do
31
+ it "returns it" do
32
+ @indexer.should_receive(:tokenizer).once.with
33
+
34
+ @indexer.tokenizer
35
+ end
36
+ end
37
+
38
+ describe "index" do
39
+ it "should execute! the indexer" do
40
+ @indexer.should_receive(:process).once.with
41
+
42
+ @indexer.index
43
+ end
44
+ end
45
+
46
+ describe "source" do
47
+ it "returns the one given to is" do
48
+ @indexer.source.should == @source
49
+ end
50
+ end
51
+
52
+ describe "raise_no_source" do
53
+ it "should raise" do
54
+ lambda { @indexer.raise_no_source }.should raise_error(Indexers::NoSourceSpecifiedException)
55
+ end
56
+ end
57
+
58
+ describe "chunked" do
59
+
60
+ end
61
+
62
+ end
@@ -4,9 +4,11 @@ describe Indexing::Bundle do
4
4
 
5
5
  before(:each) do
6
6
  @category = stub :category, :name => :some_category
7
- @type = stub :type, :name => :some_type
7
+ @index = stub :index, :name => :some_index
8
+ @configuration = Configuration::Index.new @index, @category
9
+
8
10
  @partial_strategy = Cacher::Partial::Substring.new :from => 1
9
- @exact = Indexing::Bundle.new :some_name, @category, @type, nil, @partial_strategy, nil
11
+ @exact = Indexing::Bundle.new :some_name, @configuration, nil, @partial_strategy, nil
10
12
  end
11
13
 
12
14
  def generate_random_keys amount
@@ -26,14 +28,14 @@ describe Indexing::Bundle do
26
28
  describe 'speed' do
27
29
  context 'medium arrays' do
28
30
  before(:each) do
29
- random_keys = generate_random_keys 500
30
- random_ids = generate_random_ids 500
31
+ random_keys = generate_random_keys 300
32
+ random_ids = generate_random_ids 300
31
33
  @exact.index = Hash[random_keys.zip(random_ids)]
32
34
  end
33
35
  it 'should be fast' do
34
36
  performance_of do
35
37
  @exact.generate_partial
36
- end.should < 0.2
38
+ end.should < 0.1
37
39
  end
38
40
  end
39
41
  end