redcar 0.9.0 → 0.9.1
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.
- data/CHANGES +5 -0
- data/Rakefile +1 -2
- data/lib/redcar/installer.rb +2 -1
- data/lib/redcar.rb +2 -2
- data/plugins/project_search/vendor/lucene/CHANGELOG +147 -0
- data/plugins/project_search/vendor/lucene/CONTRIBUTORS +17 -0
- data/plugins/project_search/vendor/lucene/Gemfile +9 -0
- data/plugins/project_search/vendor/lucene/Gemfile.lock +33 -0
- data/plugins/project_search/vendor/lucene/LICENSE +19 -0
- data/plugins/project_search/vendor/lucene/README.rdoc +283 -0
- data/plugins/project_search/vendor/lucene/Rakefile +35 -0
- data/plugins/project_search/vendor/lucene/examples/active_model/serializers.rb +25 -0
- data/plugins/project_search/vendor/lucene/examples/active_model/validation.rb +26 -0
- data/plugins/project_search/vendor/lucene/examples/admin/Rakefile +4 -0
- data/plugins/project_search/vendor/lucene/examples/admin/admin.rb +29 -0
- data/plugins/project_search/vendor/lucene/examples/admin/public/jquery.js +4376 -0
- data/plugins/project_search/vendor/lucene/examples/admin/public/neo4j.css +153 -0
- data/plugins/project_search/vendor/lucene/examples/admin/public/neo_admin.js +18 -0
- data/plugins/project_search/vendor/lucene/examples/admin/spec/admin_spec.rb +26 -0
- data/plugins/project_search/vendor/lucene/examples/admin/views/index.erb +21 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/README.rdoc +9 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/app.rb +7 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/batch.props +5 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/features/step_definitions/add_steps.rb +121 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/features/support/env.rb +30 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/features/support/rspec_helper.rb +50 -0
- data/plugins/project_search/vendor/lucene/examples/filetree/features/treesizes.feature +19 -0
- data/plugins/project_search/vendor/lucene/examples/imdb/1_create_neo_db.rb +66 -0
- data/plugins/project_search/vendor/lucene/examples/imdb/2_index_db.rb +23 -0
- data/plugins/project_search/vendor/lucene/examples/imdb/README +12 -0
- data/plugins/project_search/vendor/lucene/examples/imdb/find_actors.rb +56 -0
- data/plugins/project_search/vendor/lucene/examples/imdb/install.sh +12 -0
- data/plugins/project_search/vendor/lucene/examples/imdb/model.rb +37 -0
- data/plugins/project_search/vendor/lucene/examples/railway/README +111 -0
- data/plugins/project_search/vendor/lucene/examples/railway/railnet-app.rb +31 -0
- data/plugins/project_search/vendor/lucene/examples/railway/railnet-data.rb +42 -0
- data/plugins/project_search/vendor/lucene/examples/rest/example.rb +41 -0
- data/plugins/project_search/vendor/lucene/examples/you_might_know/YouMightKnow.java +60 -0
- data/plugins/project_search/vendor/lucene/examples/you_might_know/all_simple_paths.rb +34 -0
- data/plugins/project_search/vendor/lucene/examples/you_might_know/nodes.rb +34 -0
- data/plugins/project_search/vendor/lucene/examples/you_might_know/you_might_know.rb +50 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/config.rb +145 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/document.rb +96 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/field_info.rb +144 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/hits.rb +54 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/index.rb +267 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/index_info.rb +146 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/index_searcher.rb +157 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/jars.rb +5 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/query_dsl.rb +135 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/transaction.rb +117 -0
- data/plugins/project_search/vendor/lucene/lib/lucene/version.rb +3 -0
- data/plugins/project_search/vendor/lucene/lib/lucene.rb +15 -0
- data/plugins/project_search/vendor/lucene/lucene.gemspec +23 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/document_spec.rb +32 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/field_info_spec.rb +70 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/index_info_spec.rb +76 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/index_spec.rb +643 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/query_dsl_spec.rb +142 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/sort_spec.rb +101 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/spec_helper.rb +10 -0
- data/plugins/project_search/vendor/lucene/spec/lucene/transaction_spec.rb +118 -0
- metadata +62 -4
@@ -0,0 +1,643 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
|
2
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/..")
|
3
|
+
require 'lucene'
|
4
|
+
require 'lucene/spec_helper'
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
describe Index, '(one uncommited document)' do
|
9
|
+
before(:each) do
|
10
|
+
setup_lucene
|
11
|
+
@index = Index.new('my_index')
|
12
|
+
@index.clear
|
13
|
+
@index << {:id => '42', :name => 'andreas'}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a to_s method with which says: index path and number of not commited documents" do
|
17
|
+
@index.to_s.should == "Index [path: 'my_index', 1 documents]"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be empty after clear" do
|
21
|
+
# when
|
22
|
+
@index.clear
|
23
|
+
|
24
|
+
# then
|
25
|
+
@index.uncommited.size.should == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be empty after commit" do
|
29
|
+
# when
|
30
|
+
@index.commit
|
31
|
+
|
32
|
+
# then
|
33
|
+
@index.uncommited.size.should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "contains one uncommited document" do
|
37
|
+
# then
|
38
|
+
@index.uncommited.size.should == 1
|
39
|
+
@index.uncommited['42'][:id].should == '42'
|
40
|
+
@index.uncommited['42'][:name].should == 'andreas'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
describe Index, '(no uncommited documents)' do
|
46
|
+
before(:each) do
|
47
|
+
setup_lucene
|
48
|
+
@index = Index.new 'myindex'
|
49
|
+
@index.clear
|
50
|
+
end
|
51
|
+
|
52
|
+
it "has a to_s method with which says: index path and no uncommited documents" do
|
53
|
+
@index.to_s.should == "Index [path: 'myindex', 0 documents]"
|
54
|
+
end
|
55
|
+
|
56
|
+
it "has no uncommited documents" do
|
57
|
+
@index.uncommited.size.should == 0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
describe Index, ".find (range)" do
|
63
|
+
before(:each) do
|
64
|
+
setup_lucene
|
65
|
+
@index = Index.new('some_index')
|
66
|
+
@index.field_infos[:id][:type] = Fixnum
|
67
|
+
@index.field_infos[:value][:type] = Fixnum
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should find docs using an inclusive range query" do
|
71
|
+
# given
|
72
|
+
@docs = {}
|
73
|
+
for i in 1..5 do
|
74
|
+
@index << {:id => i, :value=>i}
|
75
|
+
@docs[i] = @index.uncommited[i]
|
76
|
+
end
|
77
|
+
@index.commit
|
78
|
+
|
79
|
+
# when
|
80
|
+
result = @index.find(:value => 2..4)
|
81
|
+
|
82
|
+
# then
|
83
|
+
result.size.should == 3
|
84
|
+
result.should include(@docs[2], @docs[3], @docs[4])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should find docs using an inclusive range query with padding 0's" do
|
88
|
+
# given
|
89
|
+
@index << {:id => 3, :value=>3}
|
90
|
+
@index << {:id => 30, :value=>30}
|
91
|
+
@index << {:id => 32, :value=>32}
|
92
|
+
@index << {:id => 100, :value=>100}
|
93
|
+
doc30 = @index.uncommited[30]
|
94
|
+
doc32 = @index.uncommited[32]
|
95
|
+
@index.commit
|
96
|
+
|
97
|
+
# when
|
98
|
+
result = @index.find(:value => 30..35)
|
99
|
+
|
100
|
+
# then
|
101
|
+
result.size.should == 2
|
102
|
+
result.should include(doc30, doc32)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
describe Index, ".find (with TOKENIZED index)" do
|
109
|
+
before(:each) do
|
110
|
+
setup_lucene
|
111
|
+
@index = Index.new('my index')
|
112
|
+
@index.field_infos[:name][:tokenized] = true
|
113
|
+
|
114
|
+
@index << {:id => "1", :name => 'hej hopp', :name2=>'hej hopp'}
|
115
|
+
@index << {:id => "2", :name => 'hello world', :name2=>'hej hopp'}
|
116
|
+
@index << {:id => "3", :name => 'hello there', :name2=>'hej hopp'}
|
117
|
+
@index << {:id => "4", :name => ['hello', 'hej', '123']}
|
118
|
+
@doc1 = @index.uncommited["1"]
|
119
|
+
@doc2 = @index.uncommited["2"]
|
120
|
+
@doc3 = @index.uncommited["3"]
|
121
|
+
@doc4 = @index.uncommited["4"]
|
122
|
+
@index.commit
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should find indexed documents using the tokenized field" do
|
126
|
+
result = @index.find(:name=>"hello")
|
127
|
+
result.size.should == 3
|
128
|
+
result.should include(@doc2, @doc3, @doc4)
|
129
|
+
|
130
|
+
result = @index.find(:name=>"world")
|
131
|
+
result.size.should == 1
|
132
|
+
result.should include(@doc2)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should find indexed documents using the tokenized field" do
|
136
|
+
result = @index.find("name:he*")
|
137
|
+
result.size.should == 4
|
138
|
+
result.should include(@doc1, @doc2, @doc3)
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should not find stopwords like 'there'" do
|
142
|
+
result = @index.find(:name=>"there")
|
143
|
+
result.size.should == 0
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should not find indexed documents using the untokenized field" do
|
147
|
+
result = @index.find(:name2=>"hello")
|
148
|
+
result.size.should == 0
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe Index, "#find (with string queries)" do
|
153
|
+
before(:each) do
|
154
|
+
setup_lucene
|
155
|
+
@index = Index.new('myindex')
|
156
|
+
@index.field_infos[:name] = FieldInfo.new(:store => true)
|
157
|
+
@index << {:id => "1", :name => 'name1', :value=>1, :group=>'a'}
|
158
|
+
@index << {:id => "2", :name => 'name2', :value=>2, :group=>'a'}
|
159
|
+
@index << {:id => "3", :name => 'name3', :value=>2, :group=>'b'}
|
160
|
+
@index << {:id => "4", :name => ['abc', 'def', '123']}
|
161
|
+
@doc1 = @index.uncommited["1"]
|
162
|
+
@doc2 = @index.uncommited["2"]
|
163
|
+
@doc3 = @index.uncommited["3"]
|
164
|
+
@doc4 = @index.uncommited["4"]
|
165
|
+
@index.commit
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
it "should find a doc by only using its id, index.find('1')" do
|
170
|
+
r = @index.find("1")
|
171
|
+
r.size.should == 1
|
172
|
+
r.should include(@doc1)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "should find a doc with a specified field, index.find('name:\"name1\"')" do
|
176
|
+
r = @index.find("name:'name2'")
|
177
|
+
r.size.should == 1
|
178
|
+
r.should include(@doc2)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should find a doc with wildcard queries" do
|
182
|
+
r = @index.find("name:name*")
|
183
|
+
r.size.should == 3
|
184
|
+
r.should include(@doc2)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "should find handle OR queries" do
|
188
|
+
r = @index.find('group:\"b\" OR name:\"name1\"')
|
189
|
+
r.size.should == 2
|
190
|
+
r.should include(@doc3, @doc1)
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
|
196
|
+
describe Index, ".find (exact match)" do
|
197
|
+
before(:each) do
|
198
|
+
setup_lucene
|
199
|
+
@index = Index.new('myindex')
|
200
|
+
@index.field_infos[:name] = FieldInfo.new(:store => true)
|
201
|
+
@index << {:id => "1", :name => 'name1', :value=>1, :group=>'a'}
|
202
|
+
@index << {:id => "2", :name => 'name2', :value=>2, :group=>'a'}
|
203
|
+
@index << {:id => "3", :name => 'name3', :value=>2, :group=>'b'}
|
204
|
+
@index << {:id => "4", :name => ['abc', 'def', '123']}
|
205
|
+
@doc1 = @index.uncommited["1"]
|
206
|
+
@doc2 = @index.uncommited["2"]
|
207
|
+
@doc3 = @index.uncommited["3"]
|
208
|
+
@doc4 = @index.uncommited["4"]
|
209
|
+
@index.commit
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should find indexed documents using the id field" do
|
213
|
+
result = @index.find(:id=>"1")
|
214
|
+
result.size.should == 1
|
215
|
+
result.should include(@doc1)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should find indexed documents using any field" do
|
219
|
+
result = @index.find(:name=>"name1")
|
220
|
+
result.size.should == 1
|
221
|
+
result.should include(@doc1)
|
222
|
+
|
223
|
+
result = @index.find(:value=>1)
|
224
|
+
result.size.should == 1
|
225
|
+
result.should include(@doc1)
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should find nothing if it does not exist" do
|
229
|
+
result = @index.find(:name=>"name")
|
230
|
+
result.should be_empty
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
it "should find several documents having the same property" do
|
235
|
+
result = @index.find(:value => 2)
|
236
|
+
result.size.should == 2
|
237
|
+
result.should include(@doc2, @doc3)
|
238
|
+
end
|
239
|
+
|
240
|
+
it "should find using several fields" do
|
241
|
+
result = @index.find(:value => 2, :group => 'a')
|
242
|
+
result.size.should == 1
|
243
|
+
result.should include(@doc2)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "should find a document that has several values for the same key" do
|
247
|
+
result = @index.find(:name => 'def')
|
248
|
+
result.size.should == 1
|
249
|
+
result.should include(@doc4)
|
250
|
+
|
251
|
+
result = @index.find(:name => '123')
|
252
|
+
result.size.should == 1
|
253
|
+
result.should include(@doc4)
|
254
|
+
|
255
|
+
result = @index.find(:name => 'ojo')
|
256
|
+
result.size.should == 0
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should return document containing the stored fields for that index" do
|
260
|
+
# when
|
261
|
+
result = @index.find(:id=>"1")
|
262
|
+
|
263
|
+
# then
|
264
|
+
doc = result[0]
|
265
|
+
doc.id.should == '1'
|
266
|
+
doc[:name].should == 'name1'
|
267
|
+
doc[:value].should be_nil # since its default FieldInfo has :store=>false
|
268
|
+
end
|
269
|
+
|
270
|
+
end
|
271
|
+
|
272
|
+
describe Index, "<< (add documents to be commited)" do
|
273
|
+
before(:each) do
|
274
|
+
setup_lucene
|
275
|
+
@index = Index.new('myindex')
|
276
|
+
@index.field_infos[:foo] = FieldInfo.new(:store => true)
|
277
|
+
end
|
278
|
+
|
279
|
+
it "converts all fields into strings" do
|
280
|
+
@index << {:id => 42, :foo => 1}
|
281
|
+
@index.uncommited['42'][:foo].should == '1'
|
282
|
+
end
|
283
|
+
|
284
|
+
it "can add several documents" do
|
285
|
+
@index << {:id => "1", :foo => 'a'} << {:id => "2", :foo => 'b'}
|
286
|
+
|
287
|
+
# then
|
288
|
+
@index.uncommited.size.should == 2
|
289
|
+
@index.uncommited['1'][:foo].should == 'a'
|
290
|
+
@index.uncommited['2'][:foo].should == 'b'
|
291
|
+
end
|
292
|
+
|
293
|
+
it "can have several values for the same key" do
|
294
|
+
@index << {:id => 42, :name => ['foo', 'bar', 'baaz']}
|
295
|
+
@index.uncommited['42'][:name].should == ['foo', 'bar', 'baaz']
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
describe Index, ".id_field" do
|
300
|
+
before(:each) do
|
301
|
+
setup_lucene
|
302
|
+
end
|
303
|
+
|
304
|
+
it "has a default" do
|
305
|
+
index = Index.new 'myindex'
|
306
|
+
index.id_field.should == :id
|
307
|
+
end
|
308
|
+
|
309
|
+
it "can have a specified one" do
|
310
|
+
index = Index.new('myindex')
|
311
|
+
index.field_infos.id_field = :my_id
|
312
|
+
index.id_field.should == :my_id
|
313
|
+
end
|
314
|
+
|
315
|
+
it "is used to find uncommited documents" do
|
316
|
+
# given
|
317
|
+
index = Index.new('myindex')
|
318
|
+
index.field_infos.id_field = :my_id
|
319
|
+
index << {:my_id => '123', :name=>"foo"}
|
320
|
+
|
321
|
+
# when then
|
322
|
+
index.uncommited['123'][:name].should == 'foo'
|
323
|
+
end
|
324
|
+
|
325
|
+
it "can be used to delete documents" do
|
326
|
+
# given
|
327
|
+
index = Index.new('myindex')
|
328
|
+
index.field_infos.id_field = :my_id
|
329
|
+
index.field_infos[:my_id][:type] = Fixnum
|
330
|
+
index << {:my_id => 123, :name=>"foo"}
|
331
|
+
index.commit
|
332
|
+
index.find(:name=>'foo').should_not be_empty
|
333
|
+
|
334
|
+
# when delete it
|
335
|
+
index.delete(123)
|
336
|
+
index.commit
|
337
|
+
|
338
|
+
# then
|
339
|
+
index.find(:name=>'foo').should be_empty
|
340
|
+
end
|
341
|
+
|
342
|
+
it "must be included in all documents" do
|
343
|
+
# given
|
344
|
+
index = Index.new('myindex')
|
345
|
+
index.field_infos.id_field = :my_id
|
346
|
+
# when not included
|
347
|
+
lambda {
|
348
|
+
index << {:id=>2, :name=>"foo"} # my_id missing
|
349
|
+
}.should raise_error # then it should raise an exception
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
describe Index, ".new" do
|
354
|
+
it "should not create a new instance if one already exists (singelton)" do
|
355
|
+
index1 = Index.new($INDEX_DIR)
|
356
|
+
index2 = Index.new($INDEX_DIR)
|
357
|
+
index1.object_id.should == index2.object_id
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should be possible to create a new instance even if one already exists" do
|
361
|
+
index1 = Index.new($INDEX_DIR)
|
362
|
+
index1.clear
|
363
|
+
index2 = Index.new($INDEX_DIR)
|
364
|
+
index1.object_id.should_not == index2.object_id
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
describe Index, ".field_infos" do
|
369
|
+
before(:each) do
|
370
|
+
setup_lucene
|
371
|
+
@index = Index.new('myindex')
|
372
|
+
@index.clear
|
373
|
+
end
|
374
|
+
|
375
|
+
it "has a default value for the id_field - store => true" do
|
376
|
+
@index.field_infos[:id][:store].should == true
|
377
|
+
$LUCENE_LOGGER.level = Logger::INFO
|
378
|
+
end
|
379
|
+
|
380
|
+
it "has a default for unspecified fields" do
|
381
|
+
@index.field_infos[:foo].should == IndexInfo::DEFAULTS
|
382
|
+
end
|
383
|
+
|
384
|
+
it "should use a default for unspecified type, for example all fields has default :type => String" do
|
385
|
+
@index.field_infos[:value] = FieldInfo.new(:store => true, :foo => 1)
|
386
|
+
|
387
|
+
# should use default field info for unspecified
|
388
|
+
@index.field_infos[:value][:type].should == String
|
389
|
+
end
|
390
|
+
|
391
|
+
it "has a default that can be overridden" do
|
392
|
+
# given
|
393
|
+
@index.field_infos[:bar][:type] = Float
|
394
|
+
# then
|
395
|
+
@index.field_infos[:bar][:type].should == Float
|
396
|
+
@index.field_infos[:id][:type].should == String
|
397
|
+
@index.field_infos[:name][:type].should == String
|
398
|
+
end
|
399
|
+
|
400
|
+
it "can be used to convert properties" do
|
401
|
+
#given
|
402
|
+
@index.field_infos[:bar][:store] = true
|
403
|
+
@index.field_infos[:bar][:type] = Float
|
404
|
+
@index.field_infos[:id][:type] = Fixnum
|
405
|
+
@index.field_infos[:name][:store] = true
|
406
|
+
|
407
|
+
@index << {:id => 1, :bar => 3.14, :name => "andreas"}
|
408
|
+
@index.commit
|
409
|
+
|
410
|
+
# when
|
411
|
+
hits = @index.find(:name => 'andreas')
|
412
|
+
|
413
|
+
@index.field_infos[:id][:type].should == Fixnum
|
414
|
+
# then
|
415
|
+
hits.size.should == 1
|
416
|
+
hits[0][:id].should == 1
|
417
|
+
hits[0][:bar].should == 3.14
|
418
|
+
hits[0][:name].should == 'andreas'
|
419
|
+
end
|
420
|
+
|
421
|
+
|
422
|
+
it "can be used to convert and store Date field" do
|
423
|
+
#given
|
424
|
+
@index.field_infos[:since][:store] = true
|
425
|
+
@index.field_infos[:since][:type] = Date
|
426
|
+
|
427
|
+
@index << {:id => 1, :since => Date.new(2008, 3, 26)}
|
428
|
+
@index.commit
|
429
|
+
|
430
|
+
# when
|
431
|
+
hits = @index.find(:id => "1")
|
432
|
+
|
433
|
+
# then
|
434
|
+
hits.size.should == 1
|
435
|
+
hits[0][:since].should be_instance_of(Date)
|
436
|
+
hits[0][:since].year.should == 2008
|
437
|
+
hits[0][:since].month.should == 3
|
438
|
+
hits[0][:since].day.should == 26
|
439
|
+
end
|
440
|
+
|
441
|
+
|
442
|
+
it "can be used to convert and store DateTime field" do
|
443
|
+
#given
|
444
|
+
@index.field_infos[:since][:store] = true
|
445
|
+
@index.field_infos[:since][:type] = DateTime
|
446
|
+
date = DateTime.new(2008, 12, 18, 11, 4, 59)
|
447
|
+
@index << {:id => 1, :since => date}
|
448
|
+
@index.commit
|
449
|
+
|
450
|
+
# when
|
451
|
+
hits = @index.find(:id => "1")
|
452
|
+
|
453
|
+
# then
|
454
|
+
hits.size.should == 1
|
455
|
+
hits[0][:since].should be_instance_of(DateTime)
|
456
|
+
hits[0][:since].year.should == 2008
|
457
|
+
hits[0][:since].month.should == 12
|
458
|
+
hits[0][:since].day.should == 18
|
459
|
+
hits[0][:since].hour.should == 11
|
460
|
+
hits[0][:since].min.should == 4
|
461
|
+
hits[0][:since].sec.should == 59
|
462
|
+
end
|
463
|
+
|
464
|
+
end
|
465
|
+
|
466
|
+
describe Index, " when updating a document" do
|
467
|
+
before(:each) do
|
468
|
+
setup_lucene
|
469
|
+
@index = Index.new('myindex')
|
470
|
+
end
|
471
|
+
|
472
|
+
it "should remove the field if set to nil" do
|
473
|
+
# given
|
474
|
+
@index << {:id => 'a', :name=>'andreas'}
|
475
|
+
@index.commit
|
476
|
+
@index.find(:name => 'andreas').size.should == 1
|
477
|
+
|
478
|
+
# when
|
479
|
+
@index << {:id => 'a', :name=>nil}
|
480
|
+
@index.commit
|
481
|
+
|
482
|
+
# then
|
483
|
+
@index.find(:name => 'andreas').size.should == 0
|
484
|
+
end
|
485
|
+
|
486
|
+
|
487
|
+
it "should not find the old field if the field has been changed" do
|
488
|
+
# given
|
489
|
+
@index << {:id => 'a', :name=>'andreas'}
|
490
|
+
@index.commit
|
491
|
+
@index.find(:name => 'andreas').should_not be_empty
|
492
|
+
|
493
|
+
# when it change
|
494
|
+
@index << {:id => 'a', :name=>'foo'}
|
495
|
+
@index.commit
|
496
|
+
|
497
|
+
# then it can not be found
|
498
|
+
@index.find(:name => 'andreas').should be_empty
|
499
|
+
end
|
500
|
+
|
501
|
+
it "should not find a deleted document" do
|
502
|
+
# given
|
503
|
+
@index << {:id => 'a', :name=>'andreas'}
|
504
|
+
@index.commit
|
505
|
+
@index.find(:name => 'andreas').should_not be_empty
|
506
|
+
|
507
|
+
# when it is deleted
|
508
|
+
@index.delete('a')
|
509
|
+
@index.commit
|
510
|
+
|
511
|
+
# then it can not be found
|
512
|
+
@index.find(:name => 'andreas').should be_empty
|
513
|
+
end
|
514
|
+
|
515
|
+
it "should find documents that have the same properties" do
|
516
|
+
# given
|
517
|
+
@index << {:id => 'a', :name=>'bar'}
|
518
|
+
@index << {:id => 'a.1', :name=>'bar'}
|
519
|
+
|
520
|
+
@index.commit
|
521
|
+
res = @index.find(:name => 'bar')
|
522
|
+
res.size.should == 2
|
523
|
+
end
|
524
|
+
|
525
|
+
|
526
|
+
describe "Indexing with Dates" do
|
527
|
+
before(:each) do
|
528
|
+
setup_lucene
|
529
|
+
@index = Index.new('myindex')
|
530
|
+
@index.field_infos[:since][:store] = false
|
531
|
+
@index.field_infos[:since][:type] = Date
|
532
|
+
|
533
|
+
@index.field_infos[:born][:store] = false
|
534
|
+
@index.field_infos[:born][:type] = DateTime
|
535
|
+
end
|
536
|
+
|
537
|
+
|
538
|
+
it "can find an index using a date" do
|
539
|
+
#given
|
540
|
+
@index << {:id => 1, :since => Date.new(2008, 4, 26)}
|
541
|
+
@index.commit
|
542
|
+
|
543
|
+
# when
|
544
|
+
hits = @index.find(:since => Date.new(2008, 4, 26))
|
545
|
+
|
546
|
+
# then
|
547
|
+
hits.size.should == 1
|
548
|
+
hits[0][:id].should == '1'
|
549
|
+
end
|
550
|
+
|
551
|
+
it "can find an index using a Date range" do
|
552
|
+
#given
|
553
|
+
@index << {:id => 1, :since => Date.new(2008, 4, 26)}
|
554
|
+
@index.commit
|
555
|
+
|
556
|
+
# then
|
557
|
+
@index.find("since:[20080427 TO 20100203]").size.should == 0
|
558
|
+
@index.find("since:[20080422 TO 20080425]").size.should == 0
|
559
|
+
@index.find("since:{20080426 TO 20090425}").size.should == 0
|
560
|
+
@index.find("since:[20080426 TO 20090203]")[0][:id].should == '1'
|
561
|
+
@index.find("since:[20080425 TO 20080426]")[0][:id].should == '1'
|
562
|
+
@index.find("since:[20000425 TO 20200426]")[0][:id].should == '1'
|
563
|
+
end
|
564
|
+
|
565
|
+
it "can find an index using a DateTime range" do
|
566
|
+
#given
|
567
|
+
# only UTC times are supported
|
568
|
+
@index << {:id => 1, :born => DateTime.civil(2008, 4, 26, 15, 58, 02)}
|
569
|
+
@index.commit
|
570
|
+
|
571
|
+
# then
|
572
|
+
@index.find("born:[20080427 TO 20100203]").size.should == 0
|
573
|
+
@index.find("born:[20080422 TO 20080425]").size.should == 0
|
574
|
+
@index.find("born:[20080426 TO 20090203]")[0][:id].should == '1'
|
575
|
+
@index.find("born:[20080425 TO 20080427]")[0][:id].should == '1'
|
576
|
+
@index.find("born:[20000425 TO 20200426]")[0][:id].should == '1'
|
577
|
+
|
578
|
+
@index.find("born:[200804260000 TO 200804262359]")[0][:id].should == '1'
|
579
|
+
@index.find("born:[200804261500 TO 200804261600]")[0][:id].should == '1'
|
580
|
+
@index.find("born:[200804261557 TO 200804261559]")[0][:id].should == '1'
|
581
|
+
@index.find("born:[20080426155759 TO 20080426155804]")[0][:id].should == '1'
|
582
|
+
@index.find("born:[200804261559 TO 200804261601]").size.should == 0
|
583
|
+
@index.find("born:[200804261557 TO 200804261500]").size.should == 0
|
584
|
+
end
|
585
|
+
|
586
|
+
end
|
587
|
+
end
|
588
|
+
|
589
|
+
|
590
|
+
describe Index, " #analyzer" do
|
591
|
+
before(:each) do
|
592
|
+
setup_lucene
|
593
|
+
@index = Index.new('myindex')
|
594
|
+
end
|
595
|
+
|
596
|
+
it "should default to StandardAnalyzer" do
|
597
|
+
# @index.analyzer = :keyword
|
598
|
+
|
599
|
+
# given some a stop word
|
600
|
+
@index << {:id => 'a', :name=>'it'}
|
601
|
+
@index.commit
|
602
|
+
|
603
|
+
# then it should not found it with the standard default analyzer
|
604
|
+
@index.find("name:it").should be_empty
|
605
|
+
end
|
606
|
+
|
607
|
+
it "can be set to keyword analyzer for one field" do
|
608
|
+
@index.field_infos[:code][:analyzer] = :keyword
|
609
|
+
|
610
|
+
# given some a stop word
|
611
|
+
@index << {:id => 'a', :code=>'it'}
|
612
|
+
@index.commit
|
613
|
+
|
614
|
+
# then it should not found it with the standard default analyzer
|
615
|
+
@index.find("code:it").should_not be_empty
|
616
|
+
end
|
617
|
+
|
618
|
+
|
619
|
+
it "can be set to keyword analyzer for one field and simple analyzer for another field" do
|
620
|
+
@index.field_infos[:code][:analyzer] = :keyword
|
621
|
+
@index.field_infos[:w][:analyzer] = :whitespace
|
622
|
+
@index.field_infos[:w][:tokenized] = true
|
623
|
+
|
624
|
+
@index.field_infos[:s][:analyzer] = :simple
|
625
|
+
@index.field_infos[:s][:tokenized] = true
|
626
|
+
|
627
|
+
# given some a stop word
|
628
|
+
@index << {:id => 'a', :code=>'it', :w => "XY&Z Corporation - xyz@example.com", :s => "XY&Z Corporation - xyz@example.com"}
|
629
|
+
@index.commit
|
630
|
+
|
631
|
+
# then it should not found it with the standard default analyzer
|
632
|
+
@index.find("code:it").should_not be_empty
|
633
|
+
@index.find(:w => "Corporation").should_not be_empty
|
634
|
+
@index.find(:w => "corporation").should be_empty
|
635
|
+
|
636
|
+
@index.find(:w => "XY&Z").should_not be_empty
|
637
|
+
@index.find(:w => "XY").should be_empty
|
638
|
+
|
639
|
+
@index.find(:s => "XY&Z").should be_empty
|
640
|
+
@index.find(:s => "xy").should_not be_empty
|
641
|
+
end
|
642
|
+
|
643
|
+
end
|