redcar 0.9.2 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +34 -4
- data/Rakefile +2 -1
- data/lib/redcar.rb +3 -3
- data/lib/redcar/installer.rb +2 -3
- data/plugins/application/features/step_definitions/dialog_steps.rb +7 -0
- data/plugins/application/features/step_definitions/key_steps.rb +18 -0
- data/plugins/application/features/step_definitions/menu_steps.rb +5 -6
- data/plugins/application/features/step_definitions/speedbar_steps.rb +29 -9
- data/plugins/application/features/step_definitions/tree_steps.rb +13 -0
- data/plugins/application/features/support/env.rb +39 -5
- data/plugins/application/features/support/fake_event.rb +12 -0
- data/plugins/application/lib/application.rb +5 -6
- data/plugins/application/lib/application/dialog.rb +53 -10
- data/plugins/application/lib/application/dialogs/modeless_list_dialog.rb +85 -0
- data/plugins/application/lib/application/keymap.rb +10 -8
- data/plugins/application/lib/application/menu.rb +38 -16
- data/plugins/application/lib/application/treebook.rb +30 -0
- data/plugins/application/lib/application/window.rb +20 -2
- data/plugins/application/spec/application/command/executor_spec.rb +1 -0
- data/plugins/application/spec/application/menu_spec.rb +26 -26
- data/plugins/application/spec/application/treebook_spec.rb +6 -6
- data/plugins/application/spec/spec_helper.rb +10 -1
- data/plugins/application_swt/lib/application_swt.rb +25 -3
- data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +48 -27
- data/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb +22 -11
- data/plugins/application_swt/lib/application_swt/dialogs/modeless_dialog.rb +113 -0
- data/plugins/application_swt/lib/application_swt/dialogs/modeless_html_dialog.rb +85 -0
- data/plugins/application_swt/lib/application_swt/dialogs/modeless_list_dialog_controller.rb +143 -0
- data/plugins/application_swt/lib/application_swt/gradient.rb +61 -0
- data/plugins/application_swt/lib/application_swt/menu/binding_translator.rb +4 -4
- data/plugins/application_swt/lib/application_swt/notebook.rb +5 -8
- data/plugins/application_swt/lib/application_swt/speedbar.rb +1 -0
- data/plugins/application_swt/lib/application_swt/treebook.rb +6 -8
- data/plugins/application_swt/lib/application_swt/window.rb +85 -57
- data/plugins/application_swt/lib/swt/graphics_utils.rb +23 -0
- data/plugins/application_swt/lib/swt/vtab_folder.rb +7 -0
- data/plugins/application_swt/lib/swt/vtab_label.rb +1 -1
- data/plugins/application_swt/spec/application_swt/gradient_spec.rb +142 -0
- data/plugins/auto_completer/lib/auto_completer.rb +10 -42
- data/plugins/auto_completer/lib/auto_completer/list_dialog.rb +21 -0
- data/plugins/clojure/lib/clojure.rb +33 -0
- data/plugins/{repl/lib/repl/clojure_mirror.rb → clojure/lib/clojure/repl_mirror.rb} +16 -20
- data/plugins/clojure/plugin.rb +9 -0
- data/plugins/{repl/spec/repl/clojure_mirror_spec.rb → clojure/spec/clojure/repl_mirror_spec.rb} +12 -13
- data/plugins/clojure/spec/spec_helper.rb +5 -0
- data/plugins/{repl → clojure}/vendor/Wrapper.clj +0 -0
- data/plugins/{repl → clojure}/vendor/dummy +0 -0
- data/plugins/{repl → clojure}/vendor/enclojure-wrapper.jar +0 -0
- data/plugins/connection_manager/lib/connection_manager.rb +13 -13
- data/plugins/declarations/lib/declarations.rb +17 -6
- data/plugins/document_search/features/find.feature +389 -0
- data/plugins/document_search/features/find_and_replace.feature +723 -0
- data/plugins/document_search/features/replace.feature +69 -62
- data/plugins/document_search/lib/document_search.rb +81 -64
- data/plugins/document_search/lib/document_search/commands.rb +258 -0
- data/plugins/document_search/lib/document_search/find_and_replace_speedbar.rb +142 -0
- data/plugins/document_search/lib/document_search/find_speedbar.rb +102 -0
- data/plugins/document_search/lib/document_search/query_options.rb +45 -0
- data/plugins/edit_view/features/case_change.feature +9 -5
- data/plugins/edit_view/features/step_definitions/editing_steps.rb +19 -0
- data/plugins/edit_view/lib/edit_view.rb +15 -12
- data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +12 -2
- data/plugins/edit_view/lib/edit_view/commands/text_conversion_commands.rb +1 -1
- data/plugins/edit_view/lib/edit_view/document.rb +129 -99
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +33 -15
- data/plugins/encryption/encryption.rb +2 -0
- data/plugins/find-in-project/lib/find_in_project.rb +3 -5
- data/plugins/find-in-project/lib/find_in_project/views/index.html.erb +2 -0
- data/plugins/groovy/features/step_definitions/groovy_steps.rb +2 -2
- data/plugins/groovy/features/syntax_check_groovy.feature +3 -3
- data/plugins/groovy/lib/groovy.rb +38 -0
- data/plugins/groovy/lib/groovy/commands.rb +10 -0
- data/plugins/{repl/lib/repl/groovy_mirror.rb → groovy/lib/groovy/repl_mirror.rb} +33 -13
- data/plugins/groovy/lib/{syntax_check/groovy.rb → groovy/syntax_checker.rb} +13 -8
- data/plugins/groovy/plugin.rb +5 -4
- data/plugins/{repl/spec/repl/groovy_mirror_spec.rb → groovy/spec/groovy/repl_mirror_spec.rb} +14 -13
- data/plugins/groovy/spec/spec_helper.rb +5 -0
- data/plugins/html_view/assets/json2.js +476 -0
- data/plugins/html_view/lib/html_view.rb +1 -0
- data/plugins/java/features/fixtures/test.java +0 -0
- data/plugins/java/features/support/env.rb +27 -0
- data/plugins/java/features/syntax_check_java.feature +86 -0
- data/plugins/java/lib/syntax_check/java.rb +86 -0
- data/plugins/java/plugin.rb +7 -0
- data/plugins/javascript/features/fixtures/test2.js +5 -0
- data/plugins/javascript/features/step_definitions/javascript_steps.rb +16 -0
- data/plugins/javascript/features/support/env.rb +14 -0
- data/plugins/javascript/features/syntax_check_javascript.feature +46 -3
- data/plugins/javascript/lib/syntax_check/javascript.rb +15 -9
- data/plugins/line_tools/features/trim_line.feature +49 -0
- data/plugins/line_tools/lib/line_tools.rb +5 -1
- data/plugins/mirah/README +7 -0
- data/plugins/mirah/features/fixtures/test.mirah +2 -0
- data/plugins/mirah/features/syntax_check_mirah.feature +46 -0
- data/plugins/mirah/lib/mirah.rb +43 -0
- data/plugins/mirah/lib/mirah/my_error_handler.rb +22 -0
- data/plugins/mirah/lib/mirah/repl_mirror.rb +50 -0
- data/plugins/mirah/lib/mirah/syntax_checker.rb +38 -0
- data/plugins/mirah/plugin.rb +8 -0
- data/plugins/mirah/spec/mirah/repl_mirror_spec.rb +188 -0
- data/plugins/mirah/spec/spec_helper.rb +5 -0
- data/plugins/mirah/vendor/mirah-parser.jar +0 -0
- data/plugins/pair_highlighter/lib/pair_highlighter/document_controller.rb +24 -23
- data/plugins/plugin_manager_ui/lib/plugin_manager_ui.rb +10 -1
- data/plugins/plugin_manager_ui/views/index.html.erb +2 -0
- data/plugins/project/features/find_file.feature +40 -16
- data/plugins/project/features/highlight_focussed_tab.feature +16 -10
- data/plugins/project/features/step_definitions/find_file_steps.rb +11 -0
- data/plugins/project/features/step_definitions/project_tree_steps.rb +5 -1
- data/plugins/project/features/support/env.rb +5 -0
- data/plugins/project/lib/project/commands.rb +8 -1
- data/plugins/project/lib/project/dir_controller.rb +4 -1
- data/plugins/project/lib/project/find_file_dialog.rb +16 -12
- data/plugins/project/lib/project/manager.rb +30 -1
- 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.rb +15 -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/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
- data/plugins/redcar/features/alter_font_size.feature +25 -0
- data/plugins/redcar/features/step_definitions/font_steps.rb +34 -0
- data/plugins/redcar/redcar.rb +256 -43
- data/plugins/repl/features/command_editing.feature +55 -0
- data/plugins/repl/features/command_history.feature +75 -0
- data/plugins/repl/features/step_definitions/repl_steps.rb +17 -1
- data/plugins/repl/features/support/env.rb +24 -0
- data/plugins/repl/features/support/fake_repl.rb +16 -0
- data/plugins/repl/lib/repl.rb +17 -74
- data/plugins/repl/lib/repl/repl_command.rb +20 -0
- data/plugins/repl/lib/repl/repl_mirror.rb +168 -22
- data/plugins/repl/lib/repl/repl_tab.rb +131 -6
- data/plugins/repl/plugin.rb +1 -1
- data/plugins/repl/spec/repl/repl_mirror_spec.rb +72 -0
- data/plugins/repl/spec/spec_helper.rb +1 -1
- data/plugins/repl_swt/lib/repl_swt.rb +7 -0
- data/plugins/repl_swt/lib/repl_swt/key_listener.rb +43 -0
- data/plugins/repl_swt/plugin.rb +8 -0
- data/plugins/ruby/lib/ruby.rb +35 -0
- data/plugins/{repl/lib/repl/ruby_mirror.rb → ruby/lib/ruby/repl_mirror.rb} +12 -12
- data/plugins/ruby/lib/{syntax_check/ruby.rb → ruby/syntax_checker.rb} +3 -3
- data/plugins/ruby/plugin.rb +5 -4
- data/plugins/{repl/spec/repl/ruby_mirror_spec.rb → ruby/spec/ruby/repl_mirror_spec.rb} +38 -29
- data/plugins/ruby/spec/spec_helper.rb +5 -0
- data/plugins/runnables/lib/runnables.rb +2 -0
- data/plugins/runnables/lib/runnables/command_output_controller.rb +5 -0
- data/plugins/runnables/lib/runnables/output_processor.rb +14 -3
- data/plugins/runnables/views/command_output.html.erb +3 -2
- data/plugins/scm/lib/scm.rb +4 -2
- data/plugins/scm/lib/scm/diff_mirror.rb +6 -6
- data/plugins/scm_git/lib/scm_git.rb +136 -107
- data/plugins/scm_git/lib/scm_git/change.rb +28 -19
- data/plugins/snippets/lib/snippets/explorer.rb +2 -2
- data/plugins/swt/lib/swt/full_swt.rb +1 -0
- data/plugins/syntax_check/features/step_definitions/syntax_check_steps.rb +4 -0
- data/plugins/syntax_check/features/support/env.rb +3 -0
- data/plugins/syntax_check/lib/syntax_check.rb +71 -5
- data/plugins/syntax_check/lib/syntax_check/annotation.rb +61 -0
- data/plugins/test_runner/lib/test_runner.rb +39 -0
- data/plugins/test_runner/lib/test_runner/rspec_runner.rb +20 -0
- data/plugins/test_runner/lib/test_runner/run_test_command.rb +63 -0
- data/plugins/test_runner/lib/test_runner/runnable_test_runner.rb +26 -0
- data/plugins/test_runner/plugin.rb +8 -0
- data/plugins/test_runner/spec/run_test_command_spec.rb +51 -0
- data/plugins/test_runner/spec/spec_helper.rb +5 -0
- data/plugins/textmate/lib/textmate.rb +12 -2
- data/plugins/textmate/vendor/redcar-bundles/Bundles/HTML.tmbundle/Syntaxes/HTML.plist +0 -2
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Mirah.tmbundle/Syntaxes/Mirah.plist +22 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Mirah.tmbundle/info.plist +12 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Ruby.tmbundle/Syntaxes/Ruby.plist +2 -0
- data/plugins/todo_list/lib/todo_list.rb +7 -0
- data/plugins/todo_list/lib/todo_list/todo_controller.rb +3 -1
- data/plugins/tree/lib/tree.rb +4 -0
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +5 -0
- data/plugins/web_bookmarks/lib/web_bookmarks.rb +10 -0
- metadata +137 -22
- data/plugins/document_search/features/search.feature +0 -163
- data/plugins/document_search/lib/document_search/replace_all_command.rb +0 -27
- data/plugins/document_search/lib/document_search/replace_command.rb +0 -38
- data/plugins/document_search/lib/document_search/replace_next_command.rb +0 -27
- data/plugins/document_search/lib/document_search/search_and_replace.rb +0 -81
- data/plugins/ruby/README +0 -6
@@ -0,0 +1,32 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
|
2
|
+
require 'lucene'
|
3
|
+
|
4
|
+
include Lucene
|
5
|
+
|
6
|
+
describe Document do
|
7
|
+
before(:all) do
|
8
|
+
@infos = IndexInfo.new(:my_id)
|
9
|
+
@infos[:value] = {:type => Float}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have field infos" do
|
13
|
+
doc = Document.new(@infos)
|
14
|
+
doc.field_infos.should be_equal(@infos)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should convert fields" do
|
18
|
+
#$LUCENE_LOGGER.level = Logger::DEBUG
|
19
|
+
doc = Document.new(@infos, {:my_id => 1, :value => '1.23'})
|
20
|
+
doc[:my_id].should be_kind_of(String)
|
21
|
+
doc[:value].should be_kind_of(Float)
|
22
|
+
doc[:my_id].should == "1"
|
23
|
+
doc[:value].should == 1.23
|
24
|
+
#$LUCENE_LOGGER.level = Logger::WARN
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should handle multiple fields with the same id" do
|
28
|
+
doc = Document.new(@infos, {:my_id => 1, :name => ['abc', 'def', '123']})
|
29
|
+
doc[:name].should == ['abc', 'def', '123']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
|
2
|
+
require 'lucene'
|
3
|
+
|
4
|
+
include Lucene
|
5
|
+
|
6
|
+
describe FieldInfo do
|
7
|
+
it "should have default values" do
|
8
|
+
f = FieldInfo.new({})
|
9
|
+
f.store?.should == false
|
10
|
+
f[:store].should == false
|
11
|
+
f[:type].should == String
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be possible to override default values" do
|
15
|
+
f = FieldInfo.new(:store => true)
|
16
|
+
f.store?.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should be possible to set any field" do
|
20
|
+
f = FieldInfo.new(:store => true, :foo => 1, :bar=>2)
|
21
|
+
f[:foo].should == 1
|
22
|
+
f[:bar].should == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should handle dup - create a new copy of it" do
|
26
|
+
f1 = FieldInfo.new(:store => true, :foo => 1, :bar=>2)
|
27
|
+
f1.freeze
|
28
|
+
f2 = f1.dup
|
29
|
+
f2[:store] = false
|
30
|
+
f1[:store].should be_true
|
31
|
+
f2[:store].should be_false
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should handle conversion of arrays" do
|
35
|
+
f = FieldInfo.new
|
36
|
+
c = f.convert_to_lucene(['a','b','c'])
|
37
|
+
c.should == ['a', 'b', 'c']
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should handle conversion of arrays and each value should be converted to correct type" do
|
41
|
+
f = FieldInfo.new
|
42
|
+
f[:type] = Fixnum
|
43
|
+
c = f.convert_to_lucene(['1','2','3'])
|
44
|
+
c.should == ["00000000001", "00000000002", "00000000003"]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should convert to correct ruby type from a lucene string value" do
|
48
|
+
f = FieldInfo.new
|
49
|
+
f[:type] = Fixnum
|
50
|
+
f.convert_to_ruby("123").should == 123
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should convert Dates to lucene" do
|
54
|
+
f = FieldInfo.new
|
55
|
+
f[:type] = Date
|
56
|
+
f.convert_to_lucene(Date.new(2008,12,15)).should == "20081215"
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should convert Dates from lucene" do
|
60
|
+
f = FieldInfo.new
|
61
|
+
f[:type] = Date
|
62
|
+
d = f.convert_to_ruby('20081215')
|
63
|
+
d.should be_instance_of(Date)
|
64
|
+
d.year.should == 2008
|
65
|
+
d.month.should == 12
|
66
|
+
d.day.should == 15
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,76 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + "/../../lib")
|
2
|
+
require 'lucene'
|
3
|
+
|
4
|
+
include Lucene
|
5
|
+
|
6
|
+
describe IndexInfo do
|
7
|
+
it "should have an id_field" do
|
8
|
+
f = IndexInfo.new('path')
|
9
|
+
f.id_field = :my_id
|
10
|
+
f.id_field.should == :my_id
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a default for any key" do
|
14
|
+
f = IndexInfo.new('some_path')
|
15
|
+
f[42].should == IndexInfo::DEFAULTS
|
16
|
+
IndexInfo::DEFAULTS[:store].should == false
|
17
|
+
f[42][:store].should == false
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can set a field by a hash of infos " do
|
21
|
+
# given
|
22
|
+
f = IndexInfo.new('some_path')
|
23
|
+
# when
|
24
|
+
f[:value] = {:type => Float}
|
25
|
+
# then
|
26
|
+
f[:value].should be_kind_of(FieldInfo)
|
27
|
+
f[:value][:type].should == Float
|
28
|
+
end
|
29
|
+
|
30
|
+
it "can set a field by a FieldInfo" do
|
31
|
+
# given
|
32
|
+
f = IndexInfo.new('some_path')
|
33
|
+
# when
|
34
|
+
f[:value] = FieldInfo.new(:type => Float)
|
35
|
+
# then
|
36
|
+
f[:value].should be_kind_of(FieldInfo)
|
37
|
+
f[:value][:type].should == Float
|
38
|
+
end
|
39
|
+
|
40
|
+
it "can set a individual property of a FieldInfo" do
|
41
|
+
# given
|
42
|
+
f = IndexInfo.new('some_path')
|
43
|
+
|
44
|
+
# when
|
45
|
+
f[:value][:type] = Float
|
46
|
+
|
47
|
+
# then
|
48
|
+
f[:value].should be_kind_of(FieldInfo)
|
49
|
+
f[:value][:type].should == Float
|
50
|
+
end
|
51
|
+
|
52
|
+
it "can set several individual properties of a FieldInfo" do
|
53
|
+
# given
|
54
|
+
f = IndexInfo.new('some_path')
|
55
|
+
|
56
|
+
# when
|
57
|
+
f[:value][:type] = Float
|
58
|
+
f[:foo][:type] = Fixnum
|
59
|
+
f[:value][:bar] = 42
|
60
|
+
|
61
|
+
# then
|
62
|
+
f[:value].object_id.should_not == f[:foo].object_id
|
63
|
+
|
64
|
+
f[:value][:type].should == Float
|
65
|
+
f[:foo][:type].should == Fixnum
|
66
|
+
f[:value][:bar].should == 42
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "IndexInfo::DEFAULTS" do
|
72
|
+
it "should have default values" do
|
73
|
+
IndexInfo::DEFAULTS[:store].should == false
|
74
|
+
IndexInfo::DEFAULTS[:type].should == String
|
75
|
+
end
|
76
|
+
end
|
@@ -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
|