picky 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/{lib → aux}/picky/cli.rb +50 -38
  2. data/bin/picky +1 -1
  3. data/lib/picky/application.rb +5 -2
  4. data/lib/picky/index/base.rb +88 -25
  5. data/lib/picky/index/memory.rb +8 -8
  6. data/lib/picky/index/redis.rb +8 -8
  7. data/lib/picky/index_bundle.rb +2 -2
  8. data/lib/picky/indexing/indexes.rb +6 -6
  9. data/lib/picky/internals/calculations/location.rb +54 -42
  10. data/lib/picky/internals/index/backend.rb +21 -21
  11. data/lib/picky/internals/index/file/text.rb +11 -11
  12. data/lib/picky/internals/index/files.rb +6 -6
  13. data/lib/picky/internals/index/redis.rb +14 -14
  14. data/lib/picky/internals/indexed/bundle/base.rb +2 -2
  15. data/lib/picky/internals/indexed/bundle/redis.rb +3 -3
  16. data/lib/picky/internals/indexed/category.rb +8 -9
  17. data/lib/picky/internals/indexed/wrappers/bundle/calculation.rb +25 -23
  18. data/lib/picky/internals/indexed/wrappers/bundle/location.rb +36 -34
  19. data/lib/picky/internals/indexed/wrappers/bundle/wrapper.rb +35 -33
  20. data/lib/picky/internals/indexed/wrappers/category/location.rb +27 -0
  21. data/lib/picky/internals/indexers/base.rb +28 -0
  22. data/lib/picky/internals/indexers/parallel.rb +64 -0
  23. data/lib/picky/internals/indexers/serial.rb +20 -29
  24. data/lib/picky/internals/indexing/bundle/base.rb +2 -2
  25. data/lib/picky/internals/indexing/bundle/super_base.rb +3 -3
  26. data/lib/picky/internals/indexing/category.rb +30 -27
  27. data/lib/picky/internals/indexing/index.rb +82 -27
  28. data/lib/picky/internals/indexing/wrappers/category/location.rb +27 -0
  29. data/lib/picky/internals/query/indexes.rb +1 -1
  30. data/lib/picky/internals/query/qualifiers.rb +7 -6
  31. data/lib/picky/internals/query/weights.rb +6 -0
  32. data/lib/picky/internals/shared/category.rb +52 -0
  33. data/lib/picky/internals/tokenizers/base.rb +1 -1
  34. data/lib/picky/internals/tokenizers/location.rb +54 -0
  35. data/lib/picky/loader.rb +16 -3
  36. data/lib/picky/no_source_specified_exception.rb +3 -0
  37. data/lib/picky/search.rb +44 -5
  38. data/lib/picky/sources/base.rb +2 -2
  39. data/lib/picky/sources/couch.rb +1 -1
  40. data/lib/picky/sources/csv.rb +1 -1
  41. data/lib/picky/sources/db.rb +9 -9
  42. data/lib/picky/sources/delicious.rb +1 -1
  43. data/lib/picky/sources/wrappers/base.rb +12 -13
  44. data/lib/picky/sources/wrappers/location.rb +24 -54
  45. data/lib/tasks/search.rake +4 -5
  46. data/lib/tasks/todo.rake +1 -1
  47. data/spec/{lib → aux/picky}/cli_spec.rb +13 -8
  48. data/spec/lib/application_spec.rb +21 -16
  49. data/spec/lib/index/base_spec.rb +74 -27
  50. data/spec/lib/index/redis_spec.rb +1 -1
  51. data/spec/lib/index_bundle_spec.rb +1 -1
  52. data/spec/lib/indexing/indexes_spec.rb +5 -5
  53. data/spec/lib/internals/calculations/location_spec.rb +14 -3
  54. data/spec/lib/internals/index/files_spec.rb +2 -3
  55. data/spec/lib/internals/index/redis_spec.rb +122 -49
  56. data/spec/lib/internals/indexed/bundle/memory_spec.rb +4 -6
  57. data/spec/lib/internals/indexed/bundle/redis_spec.rb +2 -3
  58. data/spec/lib/internals/indexed/wrappers/bundle/calculation_spec.rb +3 -3
  59. data/spec/lib/internals/indexed/wrappers/bundle/wrapper_spec.rb +3 -3
  60. data/spec/lib/internals/indexers/parallel_spec.rb +36 -0
  61. data/spec/lib/internals/indexers/serial_spec.rb +6 -14
  62. data/spec/lib/internals/indexing/bundle/memory_partial_generation_speed_spec.rb +2 -3
  63. data/spec/lib/internals/indexing/bundle/memory_spec.rb +5 -6
  64. data/spec/lib/internals/indexing/bundle/redis_spec.rb +5 -6
  65. data/spec/lib/internals/indexing/category_spec.rb +21 -6
  66. data/spec/lib/internals/indexing/index_spec.rb +43 -7
  67. data/spec/lib/query/indexes_spec.rb +1 -1
  68. data/spec/lib/search_spec.rb +51 -2
  69. data/spec/lib/sources/couch_spec.rb +6 -6
  70. data/spec/lib/sources/csv_spec.rb +4 -4
  71. data/spec/lib/sources/db_spec.rb +13 -14
  72. data/spec/lib/sources/delicious_spec.rb +3 -3
  73. data/spec/lib/sources/wrappers/base_spec.rb +9 -10
  74. data/spec/lib/sources/wrappers/location_spec.rb +11 -23
  75. metadata +14 -15
  76. data/lib/picky/auxiliary/terminal.rb +0 -219
  77. data/lib/picky/internals/configuration/index.rb +0 -67
  78. data/lib/picky/internals/indexers/no_source_specified_error.rb +0 -7
  79. data/lib/picky/internals/indexing/categories.rb +0 -46
  80. data/spec/lib/auxiliary/terminal_spec.rb +0 -150
  81. data/spec/lib/internals/configuration/index_spec.rb +0 -80
  82. data/spec/lib/internals/indexing/categories_spec.rb +0 -49
@@ -1,74 +1,147 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Internals::Index::Redis do
4
-
5
- let(:config) do
6
- index = stub :index, :name => :some_index
7
- category = stub :category, :name => :some_category
8
- Configuration::Index.new index, category
9
- end
10
- let(:redis) { described_class.new :some_name, config }
11
-
12
- describe 'setting' do
13
- it 'delegates to the configuration' do
14
- configuration = stub :configuration
15
- redis.stub! :configuration => configuration
16
-
17
- configuration.should_receive(:member).once.with :some_sym
18
4
 
19
- redis.setting :some_sym
5
+ context 'indexing' do
6
+ let(:category) do
7
+ index = stub :index, :name => :some_index
8
+ category = Internals::Indexing::Category.new :some_category, index
20
9
  end
21
- it 'returns the value' do
22
- configuration = stub :configuration
23
- redis.stub! :configuration => configuration
10
+ let(:redis) { described_class.new :some_name, category }
24
11
 
25
- configuration.should_receive(:member).any_number_of_times.and_return "some config"
12
+ describe 'setting' do
13
+ it 'delegates to the configuration' do
14
+ configuration = stub :configuration
15
+ redis.stub! :configuration => configuration
26
16
 
27
- redis.setting(:any).should == "some config"
28
- end
29
- end
30
- describe 'weight' do
31
- it 'delegates to the weights' do
32
- weights = stub :weights
33
- redis.stub! :weights => weights
17
+ configuration.should_receive(:member).once.with :some_sym
18
+
19
+ redis.setting :some_sym
20
+ end
21
+ it 'returns the value' do
22
+ configuration = stub :configuration
23
+ redis.stub! :configuration => configuration
34
24
 
35
- weights.should_receive(:member).once.with :some_sym
25
+ configuration.should_receive(:member).any_number_of_times.and_return "some config"
36
26
 
37
- redis.weight :some_sym
27
+ redis.setting(:any).should == "some config"
28
+ end
38
29
  end
39
- it 'returns a floated value' do
40
- weights = stub :weights
41
- redis.stub! :weights => weights
30
+ describe 'weight' do
31
+ it 'delegates to the weights' do
32
+ weights = stub :weights
33
+ redis.stub! :weights => weights
42
34
 
43
- weights.should_receive(:member).any_number_of_times.and_return "1.0"
35
+ weights.should_receive(:member).once.with :some_sym
44
36
 
45
- redis.weight(:any).should == 1.0
37
+ redis.weight :some_sym
38
+ end
39
+ it 'returns a floated value' do
40
+ weights = stub :weights
41
+ redis.stub! :weights => weights
42
+
43
+ weights.should_receive(:member).any_number_of_times.and_return "1.0"
44
+
45
+ redis.weight(:any).should == 1.0
46
+ end
47
+ it 'returns a floated value' do
48
+ weights = stub :weights
49
+ redis.stub! :weights => weights
50
+
51
+ weights.should_receive(:member).any_number_of_times.and_return 1
52
+
53
+ redis.weight(:any).should == 1.0
54
+ end
46
55
  end
47
- it 'returns a floated value' do
48
- weights = stub :weights
49
- redis.stub! :weights => weights
56
+ describe 'ids' do
57
+ it 'delegates to the index' do
58
+ index = stub :index
59
+ redis.stub! :index => index
50
60
 
51
- weights.should_receive(:member).any_number_of_times.and_return 1
61
+ index.should_receive(:collection).once.with :some_sym
52
62
 
53
- redis.weight(:any).should == 1.0
63
+ redis.ids :some_sym
64
+ end
65
+ it 'returns the value' do
66
+ index = stub :index
67
+ redis.stub! :index => index
68
+
69
+ index.should_receive(:collection).any_number_of_times.and_return [1,2,3]
70
+
71
+ redis.ids(:any).should == [1,2,3]
72
+ end
54
73
  end
55
74
  end
56
- describe 'ids' do
57
- it 'delegates to the index' do
58
- index = stub :index
59
- redis.stub! :index => index
75
+
76
+ context 'indexed' do
77
+ let(:category) do
78
+ index = stub :index, :name => :some_index
79
+ category = Internals::Indexed::Category.new :some_category, index
80
+ end
81
+ let(:redis) { described_class.new :some_name, category }
82
+
83
+ describe 'setting' do
84
+ it 'delegates to the configuration' do
85
+ configuration = stub :configuration
86
+ redis.stub! :configuration => configuration
87
+
88
+ configuration.should_receive(:member).once.with :some_sym
89
+
90
+ redis.setting :some_sym
91
+ end
92
+ it 'returns the value' do
93
+ configuration = stub :configuration
94
+ redis.stub! :configuration => configuration
95
+
96
+ configuration.should_receive(:member).any_number_of_times.and_return "some config"
97
+
98
+ redis.setting(:any).should == "some config"
99
+ end
100
+ end
101
+ describe 'weight' do
102
+ it 'delegates to the weights' do
103
+ weights = stub :weights
104
+ redis.stub! :weights => weights
60
105
 
61
- index.should_receive(:collection).once.with :some_sym
106
+ weights.should_receive(:member).once.with :some_sym
62
107
 
63
- redis.ids :some_sym
108
+ redis.weight :some_sym
109
+ end
110
+ it 'returns a floated value' do
111
+ weights = stub :weights
112
+ redis.stub! :weights => weights
113
+
114
+ weights.should_receive(:member).any_number_of_times.and_return "1.0"
115
+
116
+ redis.weight(:any).should == 1.0
117
+ end
118
+ it 'returns a floated value' do
119
+ weights = stub :weights
120
+ redis.stub! :weights => weights
121
+
122
+ weights.should_receive(:member).any_number_of_times.and_return 1
123
+
124
+ redis.weight(:any).should == 1.0
125
+ end
64
126
  end
65
- it 'returns the value' do
66
- index = stub :index
67
- redis.stub! :index => index
127
+ describe 'ids' do
128
+ it 'delegates to the index' do
129
+ index = stub :index
130
+ redis.stub! :index => index
68
131
 
69
- index.should_receive(:collection).any_number_of_times.and_return [1,2,3]
132
+ index.should_receive(:collection).once.with :some_sym
70
133
 
71
- redis.ids(:any).should == [1,2,3]
134
+ redis.ids :some_sym
135
+ end
136
+ it 'returns the value' do
137
+ index = stub :index
138
+ redis.stub! :index => index
139
+
140
+ index.should_receive(:collection).any_number_of_times.and_return [1,2,3]
141
+
142
+ redis.ids(:any).should == [1,2,3]
143
+ end
72
144
  end
73
145
  end
146
+
74
147
  end
@@ -3,12 +3,11 @@ require 'spec_helper'
3
3
  describe Internals::Indexed::Bundle::Memory do
4
4
 
5
5
  before(:each) do
6
- @category = stub :category, :name => :some_category
7
6
  @index = stub :index, :name => :some_index
8
- @configuration = Configuration::Index.new @index, @category
7
+ @category = Internals::Indexed::Category.new :some_category, @index
9
8
 
10
9
  @similarity = stub :similarity
11
- @bundle = described_class.new :some_name, @configuration, @similarity
10
+ @bundle = described_class.new :some_name, @category, @similarity
12
11
  end
13
12
 
14
13
  describe 'to_s' do
@@ -161,11 +160,10 @@ Memory
161
160
 
162
161
  describe 'initialization' do
163
162
  before(:each) do
164
- @category = stub :category, :name => :some_category
165
163
  @index = stub :index, :name => :some_index
166
- @configuration = Configuration::Index.new @index, @category
164
+ @category = Internals::Indexed::Category.new :some_category, @index
167
165
 
168
- @bundle = described_class.new :some_name, @configuration, :similarity
166
+ @bundle = described_class.new :some_name, @category, :similarity
169
167
  end
170
168
  it 'should initialize the index correctly' do
171
169
  @bundle.index.should == {}
@@ -7,12 +7,11 @@ describe Internals::Indexed::Bundle::Redis do
7
7
 
8
8
  Internals::Index::Redis.stub! :new => @backend
9
9
 
10
- @category = stub :category, :name => :some_category
11
10
  @index = stub :index, :name => :some_index
12
- @configuration = Configuration::Index.new @index, @category
11
+ @category = Internals::Indexed::Category.new :some_category, @index
13
12
 
14
13
  @similarity = stub :similarity
15
- @bundle = described_class.new :some_name, @configuration, @similarity
14
+ @bundle = described_class.new :some_name, @category, @similarity
16
15
  end
17
16
 
18
17
  describe 'ids' do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexed::Wrappers::Bundle::Calculation do
3
+ describe Internals::Indexed::Wrappers::Bundle::Calculation do
4
4
 
5
5
  before(:each) do
6
- @bundle = stub :bundle
6
+ @bundle = stub :bundle
7
7
 
8
- @calculation = Indexed::Wrappers::Bundle::Calculation.new @bundle
8
+ @calculation = described_class.new @bundle
9
9
  end
10
10
 
11
11
  describe 'ids' do
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Indexed::Wrappers::Bundle::Wrapper do
3
+ describe Internals::Indexed::Wrappers::Bundle::Wrapper do
4
4
 
5
5
  before(:each) do
6
- @bundle = stub :bundle
6
+ @bundle = stub :bundle
7
7
 
8
- @calculation = Indexed::Wrappers::Bundle::Wrapper.new @bundle
8
+ @calculation = described_class.new @bundle
9
9
  end
10
10
 
11
11
  describe 'ids' do
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe Indexers::Parallel do
4
+
5
+ before(:each) do
6
+ @source = stub :source
7
+ @tokenizer = stub :tokenizer
8
+ @categories = stub :categories
9
+ @index = stub :index, :name => :some_index, :categories => @categories
10
+
11
+ @indexer = described_class.new @index
12
+ @indexer.stub! :timed_exclaim
13
+ end
14
+
15
+ describe 'flush' do
16
+ it 'flushes to joined cache to the file and clears it' do
17
+ cache = stub :cache
18
+ file = stub :file
19
+
20
+ cache.should_receive(:join).twice.and_return :joined
21
+ file.should_receive(:write).twice.with(:joined).and_return :joined
22
+ cache.should_receive(:clear).twice
23
+
24
+ @indexer.flush [[nil, cache, file], [nil, cache, file]]
25
+ end
26
+ end
27
+
28
+ describe "index" do
29
+ it "should process" do
30
+ @indexer.should_receive(:process).once.with
31
+
32
+ @indexer.index
33
+ end
34
+ end
35
+
36
+ end
@@ -3,13 +3,11 @@ require 'spec_helper'
3
3
  describe Indexers::Serial do
4
4
 
5
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
6
  @tokenizer = stub :tokenizer
12
- @indexer = Indexers::Serial.new @configuration, @source, @tokenizer
7
+ @source = stub :source
8
+ @category = stub :category, :identifier => :some_identifier, :tokenizer => @tokenizer, :source => @source
9
+
10
+ @indexer = described_class.new @category
13
11
  @indexer.stub! :timed_exclaim
14
12
  end
15
13
 
@@ -40,7 +38,7 @@ describe Indexers::Serial do
40
38
 
41
39
  describe "indexing_message" do
42
40
  it "informs the user about what it is going to index" do
43
- @indexer.should_receive(:timed_exclaim).once.with '"some_index:some_category": Starting indexing.'
41
+ @indexer.should_receive(:timed_exclaim).once.with '"some_identifier": Starting serial indexing.'
44
42
 
45
43
  @indexer.indexing_message
46
44
  end
@@ -55,7 +53,7 @@ describe Indexers::Serial do
55
53
  end
56
54
 
57
55
  describe "index" do
58
- it "should execute! the indexer" do
56
+ it "should process" do
59
57
  @indexer.should_receive(:process).once.with
60
58
 
61
59
  @indexer.index
@@ -68,12 +66,6 @@ describe Indexers::Serial do
68
66
  end
69
67
  end
70
68
 
71
- describe "raise_no_source" do
72
- it "should raise" do
73
- lambda { @indexer.raise_no_source }.should raise_error(Indexers::NoSourceSpecifiedException)
74
- end
75
- end
76
-
77
69
  describe "chunked" do
78
70
 
79
71
  end
@@ -3,12 +3,11 @@ require 'spec_helper'
3
3
  describe Internals::Indexing::Bundle::Memory do
4
4
 
5
5
  before(:each) do
6
- @category = stub :category, :name => :some_category
7
6
  @index = stub :index, :name => :some_index
8
- @configuration = Configuration::Index.new @index, @category
7
+ @category = Internals::Indexing::Category.new :some_category, @index
9
8
 
10
9
  @partial_strategy = Internals::Generators::Partial::Substring.new :from => 1
11
- @exact = described_class.new :some_name, @configuration, nil, @partial_strategy, nil
10
+ @exact = described_class.new :some_name, @category, nil, @partial_strategy, nil
12
11
  end
13
12
 
14
13
  def generate_random_keys amount
@@ -3,15 +3,14 @@ require 'spec_helper'
3
3
  describe Internals::Indexing::Bundle::Memory do
4
4
 
5
5
  before(:each) do
6
- @internal_index = stub :index, :name => :some_index
7
- @category = stub :category, :name => :some_category
8
- @configuration = Configuration::Index.new @internal_index, @category
6
+ @index = stub :index, :name => :some_index
7
+ @category = Internals::Indexing::Category.new :some_category, @index
9
8
 
10
9
  @partial = stub :partial
11
10
  @weights = stub :weights
12
11
  @similarity = stub :similarity
13
12
  end
14
- let(:index) { described_class.new :some_name, @configuration, @similarity, @partial, @weights }
13
+ let(:index) { described_class.new :some_name, @category, @similarity, @partial, @weights }
15
14
 
16
15
  describe 'raise_cache_missing' do
17
16
  it 'does something' do
@@ -65,8 +64,8 @@ describe Internals::Indexing::Bundle::Memory do
65
64
  index.stub! :files => files
66
65
 
67
66
  @ary = stub :ary
68
- @internal_index.should_receive(:[]).any_number_of_times.and_return @ary
69
- index.stub! :index => @internal_index
67
+ @index.should_receive(:[]).any_number_of_times.and_return @ary
68
+ index.stub! :index => @index
70
69
  end
71
70
  context 'id key format' do
72
71
  before(:each) do
@@ -3,15 +3,14 @@ require 'spec_helper'
3
3
  describe Internals::Indexing::Bundle::Redis do
4
4
 
5
5
  before(:each) do
6
- @internal_index = stub :index, :name => :some_index
7
- @category = stub :category, :name => :some_category
8
- @configuration = Configuration::Index.new @internal_index, @category
6
+ @index = stub :index, :name => :some_index
7
+ @category = Internals::Indexing::Category.new :some_category, @index
9
8
 
10
9
  @partial = stub :partial
11
10
  @weights = stub :weights
12
11
  @similarity = stub :similarity
13
12
  end
14
- let(:index) { described_class.new :some_name, @configuration, @similarity, @partial, @weights }
13
+ let(:index) { described_class.new :some_name, @category, @similarity, @partial, @weights }
15
14
 
16
15
  describe 'raise_cache_missing' do
17
16
  it 'does something' do
@@ -65,8 +64,8 @@ describe Internals::Indexing::Bundle::Redis do
65
64
  index.stub! :files => files
66
65
 
67
66
  @ary = stub :ary
68
- @internal_index.should_receive(:[]).any_number_of_times.and_return @ary
69
- index.stub! :index => @internal_index
67
+ @index.should_receive(:[]).any_number_of_times.and_return @ary
68
+ index.stub! :index => @index
70
69
  end
71
70
  context 'id key format' do
72
71
  before(:each) do
@@ -106,6 +106,21 @@ describe Internals::Indexing::Category do
106
106
  end
107
107
  end
108
108
 
109
+ describe 'source' do
110
+ context 'with explicit source' do
111
+ let(:category) { described_class.new(:some_category, @index, :source => :category_source) }
112
+ it 'returns the right source' do
113
+ category.source.should == :category_source
114
+ end
115
+ end
116
+ context 'without explicit source' do
117
+ let(:category) { described_class.new(:some_category, @index.tap{ |index| index.stub! :source => :index_source }) }
118
+ it 'returns the right source' do
119
+ category.source.should == :index_source
120
+ end
121
+ end
122
+ end
123
+
109
124
  describe "cache" do
110
125
  before(:each) do
111
126
  category.stub! :generate_caches
@@ -113,12 +128,12 @@ describe Internals::Indexing::Category do
113
128
  it "prepares the cache directory" do
114
129
  category.should_receive(:prepare_index_directory).once.with
115
130
 
116
- category.cache
131
+ category.cache!
117
132
  end
118
133
  it "tells the indexer to index" do
119
134
  category.should_receive(:generate_caches).once.with
120
135
 
121
- category.cache
136
+ category.cache!
122
137
  end
123
138
  end
124
139
  describe "index" do
@@ -129,18 +144,18 @@ describe Internals::Indexing::Category do
129
144
  it "prepares the cache directory" do
130
145
  category.should_receive(:prepare_index_directory).once.with
131
146
 
132
- category.index
147
+ category.index!
133
148
  end
134
149
  it "tells the indexer to index" do
135
150
  @indexer.should_receive(:index).once.with
136
151
 
137
- category.index
152
+ category.index!
138
153
  end
139
154
  end
140
155
  describe "source" do
141
156
  context "without source" do
142
- it "raises" do
143
- lambda { described_class.new :some_name, @index }.should raise_error(Indexers::NoSourceSpecifiedException)
157
+ it "has no problem with that" do
158
+ lambda { described_class.new :some_name, @index }.should_not raise_error
144
159
  end
145
160
  end
146
161
  end
@@ -6,26 +6,62 @@ describe Internals::Indexing::Index do
6
6
  before(:each) do
7
7
  @source = stub :some_source
8
8
 
9
- @categories = stub :categories
10
-
11
- @index = described_class.new :some_name, @source
9
+ @index = described_class.new :some_name, source: @source
12
10
  @index.define_category :some_category_name1
13
11
  @index.define_category :some_category_name2
14
-
15
- @index.stub! :categories => @categories
12
+ end
13
+ describe "raise_no_source" do
14
+ it "should raise" do
15
+ lambda { @index.raise_no_source }.should raise_error(NoSourceSpecifiedException)
16
+ end
17
+ end
18
+ describe 'define_source' do
19
+ it 'can be set with this method' do
20
+ @index.define_source :some_other_source
21
+
22
+ @index.source.should == :some_other_source
23
+ end
16
24
  end
17
25
  describe "generate_caches" do
18
26
  it "delegates to each category" do
19
- @categories.should_receive(:generate_caches).once.with
27
+ category1 = stub :category1
28
+ category2 = stub :category2
29
+
30
+ @index.stub! :categories => [category1, category2]
31
+
32
+ category1.should_receive(:generate_caches).once.ordered.with
33
+ category2.should_receive(:generate_caches).once.ordered.with
20
34
 
21
35
  @index.generate_caches
22
36
  end
23
37
  end
38
+ describe 'find' do
39
+ context 'no categories' do
40
+ it 'raises on none existent category' do
41
+ expect do
42
+ @index.find :some_non_existent_name
43
+ end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "some_category_name1", "some_category_name2".})
44
+ end
45
+ end
46
+ context 'with categories' do
47
+ before(:each) do
48
+ @index.define_category :some_name, :source => stub(:source)
49
+ end
50
+ it 'returns it if found' do
51
+ @index.find(:some_name).should_not == nil
52
+ end
53
+ it 'raises on none existent category' do
54
+ expect do
55
+ @index.find :some_non_existent_name
56
+ end.to raise_error(%Q{Index category "some_non_existent_name" not found. Possible categories: "some_category_name1", "some_category_name2", "some_name".})
57
+ end
58
+ end
59
+ end
24
60
  end
25
61
 
26
62
  context "no categories" do
27
63
  it "works" do
28
- described_class.new :some_name, @source
64
+ described_class.new :some_name, source: @source
29
65
  end
30
66
  end
31
67
 
@@ -6,7 +6,7 @@ describe Internals::Query::Indexes do
6
6
  n = i + 1
7
7
  name = :"index#{n}"
8
8
  indexed = :"indexed#{n}"
9
- let(name) { stub name, :indexed => stub(indexed) }
9
+ let(name) { stub name, :internal_indexed => stub(indexed) }
10
10
  end
11
11
 
12
12
  let(:indexes) { described_class.new index1, index2, index3 }
@@ -6,14 +6,63 @@ describe Search do
6
6
 
7
7
  before(:each) do
8
8
  @type = stub :type
9
- @index = stub :some_index, :indexed => @type
9
+ @index = stub :some_index, :internal_indexed => @type
10
+ end
11
+
12
+ describe 'tokenized' do
13
+ let(:search) { described_class.new }
14
+ it 'delegates to the tokenizer' do
15
+ tokenizer = stub :tokenizer
16
+ search.stub! :tokenizer => tokenizer
17
+
18
+ tokenizer.should_receive(:tokenize).once.with :some_text
19
+
20
+ search.tokenized :some_text
21
+ end
22
+ end
23
+
24
+ describe 'boost' do
25
+ let(:search) do
26
+ described_class.new do
27
+ boost [:a, :b] => +3,
28
+ [:c, :d] => -1
29
+ end
30
+ end
31
+ it 'works' do
32
+ search.weights.should == Query::Weights.new([:a, :b] => 3, [:c, :d] => -1)
33
+ end
34
+ end
35
+
36
+ describe 'tokenizer' do
37
+ context 'no tokenizer predefined' do
38
+ let(:search) { described_class.new }
39
+ it 'returns the default tokenizer' do
40
+ search.tokenizer.should == Internals::Tokenizers::Query.default
41
+ end
42
+ end
43
+ context 'tokenizer predefined' do
44
+ let(:predefined) { stub(:tokenizer, :tokenize => nil) }
45
+ context 'by way of hash' do
46
+ let(:search) { described_class.new(tokenizer: predefined) }
47
+ it 'returns the predefined tokenizer' do
48
+ search.tokenizer.should == predefined
49
+ end
50
+ end
51
+ context 'by way of DSL' do
52
+ let(:search) { pre = predefined; described_class.new { searching pre } }
53
+ it 'returns the predefined tokenizer' do
54
+ search.tokenizer.should == predefined
55
+ end
56
+ end
57
+ end
58
+
10
59
  end
11
60
 
12
61
  describe 'combinations_type_for' do
13
62
  let(:search) { described_class.new }
14
63
  it 'returns a specific Combination for a specific input' do
15
64
  some_source = stub(:source, :harvest => nil)
16
- search.combinations_type_for([Index::Memory.new(:gu, some_source)]).should == Internals::Query::Combinations::Memory
65
+ search.combinations_type_for([Index::Memory.new(:gu, source: some_source)]).should == Internals::Query::Combinations::Memory
17
66
  end
18
67
  it 'just works on the same types' do
19
68
  search.combinations_type_for([:blorf, :blarf]).should == Internals::Query::Combinations::Memory