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,157 @@
|
|
1
|
+
module Lucene
|
2
|
+
|
3
|
+
class Asc
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Specifies which fields should be sorted in ascending order
|
7
|
+
#
|
8
|
+
# ==== Parameters
|
9
|
+
# fields:: One or more fields to sort in ascending order (Array)
|
10
|
+
#
|
11
|
+
# ==== Examples
|
12
|
+
# Asc[:name, :age]
|
13
|
+
#
|
14
|
+
# ==== Returns
|
15
|
+
# An array of sort fields
|
16
|
+
#
|
17
|
+
def [](*fields)
|
18
|
+
fields.map{|x| org.apache.lucene.search.SortField.new(x.to_s)}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Desc
|
24
|
+
class << self
|
25
|
+
# Specifies which fields should be sorted in descending order
|
26
|
+
#
|
27
|
+
# ==== Block parameters
|
28
|
+
# fields:: One or more fields to sort in descending order (Array)
|
29
|
+
#
|
30
|
+
# ==== Examples
|
31
|
+
# Desc[:name, :age]
|
32
|
+
#
|
33
|
+
# ==== Returns
|
34
|
+
# An array of sort fields
|
35
|
+
#
|
36
|
+
def [](*fields)
|
37
|
+
fields.map{|x| org.apache.lucene.search.SortField.new(x.to_s, true)}
|
38
|
+
#org.apache.lucene.search.Sort.new(values.map{|x| org.apache.lucene.search.SortField.new(x.to_s, true)}.to_java(:'org.apache.lucene.search.SortField'))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Does reuse Lucene Index Search for the same index.
|
45
|
+
# Reloads the index if the index has changed.
|
46
|
+
#
|
47
|
+
class IndexSearcher
|
48
|
+
|
49
|
+
@@paths = {}
|
50
|
+
|
51
|
+
def initialize(path)
|
52
|
+
@path = path
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Only create a new object if it does not already exist for this path
|
57
|
+
#
|
58
|
+
def self.new(path)
|
59
|
+
@@paths[path] = super(path) if @@paths[path].nil?
|
60
|
+
@@paths[path]
|
61
|
+
end
|
62
|
+
|
63
|
+
def find_dsl(field_infos,&block)
|
64
|
+
exp = QueryDSL.parse(&block)
|
65
|
+
query = exp.to_lucene(field_infos)
|
66
|
+
|
67
|
+
Hits.new(field_infos, index_searcher.search(query))
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def find(field_info, query)
|
72
|
+
# are there any index for this node ?
|
73
|
+
# if not return an empty array
|
74
|
+
return [] unless exist?
|
75
|
+
|
76
|
+
#puts "QUERY #{query.inspect}" # '#{query.first.class.to_s}' value #{query.first}"
|
77
|
+
sort_by ||= query[1].delete(:sort_by) if query[1].kind_of?(Hash)
|
78
|
+
sort_by ||= query.delete(:sort_by)
|
79
|
+
#puts "QUERY sort #{sort_by}"
|
80
|
+
# TODO Refactoring ! too long and complex method
|
81
|
+
lucene_query = case query
|
82
|
+
when Array
|
83
|
+
sort_by ||= query.last.delete(:sort_by) if query.last.kind_of?(Hash)
|
84
|
+
parser = org.apache.lucene.queryParser.QueryParser.new(field_info.id_field.to_s, field_info.analyzer)
|
85
|
+
parser.parse(query.first)
|
86
|
+
when Hash
|
87
|
+
bquery = org.apache.lucene.search.BooleanQuery.new
|
88
|
+
query.each_pair do |key,value|
|
89
|
+
field = field_info[key]
|
90
|
+
q = field.convert_to_query(key, value)
|
91
|
+
bquery.add(q, org.apache.lucene.search.BooleanClause::Occur::MUST)
|
92
|
+
end
|
93
|
+
bquery
|
94
|
+
else
|
95
|
+
raise StandardError.new("Unknown type #{query.class.to_s} for find #{query}")
|
96
|
+
end
|
97
|
+
|
98
|
+
if sort_by.nil?
|
99
|
+
Hits.new(field_info, index_searcher.search(lucene_query))
|
100
|
+
else
|
101
|
+
sort = create_sort(sort_by)
|
102
|
+
Hits.new(field_info, index_searcher.search(lucene_query, sort))
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
def parse_field(field)
|
108
|
+
case field
|
109
|
+
when String,Symbol
|
110
|
+
[org.apache.lucene.search.SortField.new(field.to_s)]
|
111
|
+
when org.apache.lucene.search.SortField
|
112
|
+
[field]
|
113
|
+
when Array
|
114
|
+
raise StandardError.new("Unknown sort field '#{field}'") unless field.first.kind_of?(org.apache.lucene.search.SortField)
|
115
|
+
field
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
def create_sort(fields)
|
121
|
+
case fields
|
122
|
+
when String,Symbol
|
123
|
+
org.apache.lucene.search.Sort.new(fields.to_s)
|
124
|
+
when org.apache.lucene.search.SortField
|
125
|
+
org.apache.lucene.search.Sort.new(fields)
|
126
|
+
when Array
|
127
|
+
sorts = []
|
128
|
+
fields.each do |field|
|
129
|
+
sorts += parse_field(field)
|
130
|
+
end
|
131
|
+
org.apache.lucene.search.Sort.new(sorts.to_java(:'org.apache.lucene.search.SortField'))
|
132
|
+
else
|
133
|
+
StandardError.new("Unknown type #{fields.class.to_s}")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Checks if it needs to reload the index searcher
|
139
|
+
#
|
140
|
+
def index_searcher
|
141
|
+
if @index_reader.nil? || @index_reader.getVersion() != org.apache.lucene.index.IndexReader.getCurrentVersion(@path)
|
142
|
+
@index_reader = org.apache.lucene.index.IndexReader.open(@path)
|
143
|
+
@index_searcher = org.apache.lucene.search.IndexSearcher.new(@index_reader)
|
144
|
+
$LUCENE_LOGGER.debug("Opened new IndexSearcher for #{to_s}")
|
145
|
+
end
|
146
|
+
@index_searcher
|
147
|
+
end
|
148
|
+
|
149
|
+
#
|
150
|
+
# Returns true if the index already exists.
|
151
|
+
#
|
152
|
+
def exist?
|
153
|
+
org.apache.lucene.index.IndexReader.index_exists(@path)
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module Lucene
|
2
|
+
|
3
|
+
class Expression #:nodoc:
|
4
|
+
attr_accessor :left, :right, :op, :query
|
5
|
+
|
6
|
+
def self.new_complete(left, op, right)
|
7
|
+
expr = Expression.new
|
8
|
+
expr.left = left
|
9
|
+
expr.op = op
|
10
|
+
expr.right = right
|
11
|
+
expr
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.new_uncomplete(left, query)
|
15
|
+
expr = Expression.new
|
16
|
+
expr.left = left
|
17
|
+
expr.query = query
|
18
|
+
expr
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
@op = :==
|
23
|
+
@right = other
|
24
|
+
@query
|
25
|
+
end
|
26
|
+
|
27
|
+
def >(other)
|
28
|
+
@op = :>
|
29
|
+
@right = other
|
30
|
+
@query
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Returns the fields being used in a query
|
35
|
+
#
|
36
|
+
def _fields(fields = [])
|
37
|
+
if (@left.kind_of? Expression)
|
38
|
+
@left._fields(fields)
|
39
|
+
else
|
40
|
+
fields << @left
|
41
|
+
end
|
42
|
+
if (@right.kind_of? Expression)
|
43
|
+
@right._fields(fields)
|
44
|
+
end
|
45
|
+
fields
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_lucene(field_infos)
|
49
|
+
$LUCENE_LOGGER.debug{"QueryDSL.to_lucene '#{to_s}'"}
|
50
|
+
|
51
|
+
if @left.kind_of? Lucene::Expression
|
52
|
+
left_query = @left.to_lucene(field_infos)
|
53
|
+
raise ArgumentError.new("Right term is not an Expression, but a '#{@right.class.to_s}'") unless @right.kind_of? Lucene::Expression
|
54
|
+
right_query = @right.to_lucene(field_infos)
|
55
|
+
query = org.apache.lucene.search.BooleanQuery.new
|
56
|
+
clause = (@op == :&) ? org.apache.lucene.search.BooleanClause::Occur::MUST : org.apache.lucene.search.BooleanClause::Occur::SHOULD
|
57
|
+
query.add(left_query, clause)
|
58
|
+
query.add(right_query, clause)
|
59
|
+
return query
|
60
|
+
else
|
61
|
+
field_info = field_infos[@left]
|
62
|
+
field_info.convert_to_query(@left, @right)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s
|
67
|
+
"(#@left #@op #@right)"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class QueryDSL
|
72
|
+
attr_reader :stack
|
73
|
+
|
74
|
+
def initialize
|
75
|
+
@stack = []
|
76
|
+
#yield self
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.find(field_infos = IndexInfo.new(:id), &expr)
|
80
|
+
exp = QueryDSL.parse(&expr)
|
81
|
+
exp.to_lucene(field_infos)
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
def self.parse(&query)
|
87
|
+
query_dsl = QueryDSL.new
|
88
|
+
query_dsl.instance_eval(&query)
|
89
|
+
query_dsl.stack.last
|
90
|
+
end
|
91
|
+
|
92
|
+
def method_missing(methodname, *args)
|
93
|
+
expr = Expression.new_uncomplete(methodname, self)
|
94
|
+
@stack.push expr
|
95
|
+
expr
|
96
|
+
end
|
97
|
+
|
98
|
+
def ==(other)
|
99
|
+
puts "WRONG == '#{other}'"
|
100
|
+
end
|
101
|
+
|
102
|
+
def <=>(to)
|
103
|
+
from = @stack.last.right
|
104
|
+
@stack.last.right = Range.new(from, to)
|
105
|
+
@stack.last
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def &(other)
|
110
|
+
raise ArgumentError.new("Expected at least two expression on stack, got #{@stack.size}") if @stack.size < 2
|
111
|
+
right = @stack.pop
|
112
|
+
left = @stack.pop
|
113
|
+
expr = Expression.new_complete(left, :&, right)
|
114
|
+
@stack.push expr
|
115
|
+
self
|
116
|
+
end
|
117
|
+
|
118
|
+
def |(other)
|
119
|
+
raise ArgumentError.new("Expected at least two expression on stack, got #{@stack.size}") if @stack.size < 2
|
120
|
+
right = @stack.pop
|
121
|
+
left = @stack.pop
|
122
|
+
expr = Expression.new_complete(left, :|, right)
|
123
|
+
@stack.push expr
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def to_s
|
128
|
+
@stack.last.to_s
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
end
|
135
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Lucene
|
2
|
+
|
3
|
+
class TransactionAlreadyRunningException < StandardError; end
|
4
|
+
class TransactionNotRunningException < StandardError; end
|
5
|
+
|
6
|
+
class Transaction
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
raise TransactionAlreadyRunningException.new if Transaction.running?
|
10
|
+
Thread.current[:lucene_transaction] = self
|
11
|
+
|
12
|
+
@rollback = false
|
13
|
+
@commited = false
|
14
|
+
@indexes = {} # key is the path to index, value is the index instance
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"Transaction [commited=#@commited, rollback=#@rollback, indexes=#{@indexes.size}, object_id=#{object_id}]"
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
# Commits all registered Indexes.
|
23
|
+
# Stops this transaction (running? will be false)
|
24
|
+
#
|
25
|
+
def commit
|
26
|
+
if !@rollback
|
27
|
+
@indexes.each_value do |index|
|
28
|
+
index.commit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
@commited = true
|
32
|
+
@indexes.clear
|
33
|
+
Thread.current[:lucene_transaction] = nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def failure
|
37
|
+
@rollback = true
|
38
|
+
$LUCENE_LOGGER.debug{"Rollback Lucene Transaction"}
|
39
|
+
end
|
40
|
+
|
41
|
+
def rollback?
|
42
|
+
@rollback
|
43
|
+
end
|
44
|
+
|
45
|
+
def rollback!
|
46
|
+
@rollback = true
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Registers an index to take part of this transaction
|
51
|
+
#
|
52
|
+
def register_index(key, index)
|
53
|
+
@indexes[key] = index
|
54
|
+
$LUCENE_LOGGER.debug{"Registered index for #{index}"}
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Deregister the index so that it will not be part of the transaction
|
59
|
+
# any longer.
|
60
|
+
#
|
61
|
+
def deregister_index(index)
|
62
|
+
@indexes.delete index.path
|
63
|
+
$LUCENE_LOGGER.debug{"Deregistered index for #{index}"}
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Deregister all indexes, used for testing purpose.
|
68
|
+
#
|
69
|
+
def deregister_all_indexes
|
70
|
+
@indexes.clear
|
71
|
+
$LUCENE_LOGGER.debug{"Deregistered all index, #{@indexes.inspect}"}
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def index?(path)
|
76
|
+
@indexes[path] != nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def index(path)
|
80
|
+
@indexes[path]
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Class methods
|
85
|
+
#
|
86
|
+
class << self
|
87
|
+
def run
|
88
|
+
tx = Transaction.new
|
89
|
+
begin
|
90
|
+
yield tx
|
91
|
+
rescue => ex
|
92
|
+
tx.failure
|
93
|
+
# TODO reuse of error handling and logging
|
94
|
+
$LUCENE_LOGGER.error{"Got exception #{ex}"}
|
95
|
+
ex.backtrace.each {|t| $LUCENE_LOGGER.error(t)}
|
96
|
+
raise
|
97
|
+
ensure
|
98
|
+
tx.commit unless tx.rollback?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
#
|
103
|
+
# Returns the current transaction or nil
|
104
|
+
#
|
105
|
+
def current
|
106
|
+
Thread.current[:lucene_transaction]
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
def running?
|
111
|
+
self.current != nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib/', __FILE__)
|
2
|
+
$:.unshift lib unless $:.include?(lib)
|
3
|
+
|
4
|
+
require 'lucene/version'
|
5
|
+
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "lucene"
|
9
|
+
s.version = Lucene::VERSION
|
10
|
+
# s.platform = Gem::Platform::CURRENT # will probably support C Ruby via RJB also in the future
|
11
|
+
s.authors = "Andreas Ronge"
|
12
|
+
s.email = 'andreas.ronge@gmail.com'
|
13
|
+
s.homepage = "http://github.com/andreasronge/lucene/tree"
|
14
|
+
s.rubyforge_project = 'lucene'
|
15
|
+
s.summary = "A lucene wrapper for JRuby"
|
16
|
+
s.description = s.summary
|
17
|
+
s.require_path = 'lib'
|
18
|
+
s.files = Dir.glob("{bin,lib}/**/*") + %w(README.rdoc CHANGELOG CONTRIBUTORS Gemfile lucene.gemspec)
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = %w( README.rdoc )
|
21
|
+
s.rdoc_options = ["--quiet", "--title", "Lucene.rb", "--opname", "index.html", "--line-numbers", "--main", "README.rdoc", "--inline-source"]
|
22
|
+
s.required_ruby_version = ">= 1.8.7"
|
23
|
+
end
|