sunspot_rails 2.0.0.pre.120720 → 2.0.0.pre.120924
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -6
- data/.travis.yml +35 -0
- data/README.md +863 -0
- data/Rakefile +32 -12
- data/ci/travis.sh +67 -0
- data/sunspot/.gitignore +13 -0
- data/sunspot/Gemfile +5 -0
- data/sunspot/History.txt +258 -0
- data/{LICENSE → sunspot/LICENSE} +0 -0
- data/sunspot/Rakefile +13 -0
- data/sunspot/TODO +13 -0
- data/sunspot/lib/light_config.rb +40 -0
- data/sunspot/lib/sunspot.rb +579 -0
- data/sunspot/lib/sunspot/adapters.rb +349 -0
- data/sunspot/lib/sunspot/batcher.rb +62 -0
- data/sunspot/lib/sunspot/class_set.rb +23 -0
- data/sunspot/lib/sunspot/composite_setup.rb +202 -0
- data/sunspot/lib/sunspot/configuration.rb +53 -0
- data/sunspot/lib/sunspot/data_extractor.rb +50 -0
- data/sunspot/lib/sunspot/dsl.rb +5 -0
- data/sunspot/lib/sunspot/dsl/adjustable.rb +47 -0
- data/sunspot/lib/sunspot/dsl/field_group.rb +57 -0
- data/sunspot/lib/sunspot/dsl/field_query.rb +345 -0
- data/sunspot/lib/sunspot/dsl/fields.rb +103 -0
- data/sunspot/lib/sunspot/dsl/fulltext.rb +243 -0
- data/sunspot/lib/sunspot/dsl/function.rb +27 -0
- data/sunspot/lib/sunspot/dsl/functional.rb +44 -0
- data/sunspot/lib/sunspot/dsl/more_like_this_query.rb +56 -0
- data/sunspot/lib/sunspot/dsl/paginatable.rb +32 -0
- data/sunspot/lib/sunspot/dsl/query_facet.rb +36 -0
- data/sunspot/lib/sunspot/dsl/restriction.rb +25 -0
- data/sunspot/lib/sunspot/dsl/restriction_with_near.rb +160 -0
- data/sunspot/lib/sunspot/dsl/scope.rb +214 -0
- data/sunspot/lib/sunspot/dsl/search.rb +30 -0
- data/sunspot/lib/sunspot/dsl/standard_query.rb +122 -0
- data/sunspot/lib/sunspot/field.rb +193 -0
- data/sunspot/lib/sunspot/field_factory.rb +129 -0
- data/sunspot/lib/sunspot/indexer.rb +136 -0
- data/sunspot/lib/sunspot/query.rb +11 -0
- data/sunspot/lib/sunspot/query/abstract_field_facet.rb +55 -0
- data/sunspot/lib/sunspot/query/bbox.rb +15 -0
- data/sunspot/lib/sunspot/query/boost_query.rb +24 -0
- data/sunspot/lib/sunspot/query/common_query.rb +96 -0
- data/sunspot/lib/sunspot/query/composite_fulltext.rb +36 -0
- data/sunspot/lib/sunspot/query/connective.rb +206 -0
- data/sunspot/lib/sunspot/query/date_field_facet.rb +14 -0
- data/sunspot/lib/sunspot/query/dismax.rb +132 -0
- data/sunspot/lib/sunspot/query/field_facet.rb +41 -0
- data/sunspot/lib/sunspot/query/field_group.rb +37 -0
- data/sunspot/lib/sunspot/query/filter.rb +38 -0
- data/sunspot/lib/sunspot/query/function_query.rb +52 -0
- data/sunspot/lib/sunspot/query/geo.rb +53 -0
- data/sunspot/lib/sunspot/query/geofilt.rb +16 -0
- data/sunspot/lib/sunspot/query/highlighting.rb +62 -0
- data/sunspot/lib/sunspot/query/more_like_this.rb +61 -0
- data/sunspot/lib/sunspot/query/more_like_this_query.rb +12 -0
- data/sunspot/lib/sunspot/query/pagination.rb +42 -0
- data/sunspot/lib/sunspot/query/query_facet.rb +53 -0
- data/sunspot/lib/sunspot/query/range_facet.rb +15 -0
- data/sunspot/lib/sunspot/query/restriction.rb +308 -0
- data/sunspot/lib/sunspot/query/scope.rb +9 -0
- data/sunspot/lib/sunspot/query/sort.rb +109 -0
- data/sunspot/lib/sunspot/query/sort_composite.rb +34 -0
- data/sunspot/lib/sunspot/query/standard_query.rb +16 -0
- data/sunspot/lib/sunspot/query/text_field_boost.rb +17 -0
- data/sunspot/lib/sunspot/schema.rb +151 -0
- data/sunspot/lib/sunspot/search.rb +9 -0
- data/sunspot/lib/sunspot/search/abstract_search.rb +286 -0
- data/sunspot/lib/sunspot/search/date_facet.rb +35 -0
- data/sunspot/lib/sunspot/search/facet_row.rb +27 -0
- data/sunspot/lib/sunspot/search/field_facet.rb +88 -0
- data/sunspot/lib/sunspot/search/field_group.rb +70 -0
- data/sunspot/lib/sunspot/search/group.rb +54 -0
- data/sunspot/lib/sunspot/search/highlight.rb +38 -0
- data/sunspot/lib/sunspot/search/hit.rb +150 -0
- data/sunspot/lib/sunspot/search/hit_enumerable.rb +68 -0
- data/sunspot/lib/sunspot/search/more_like_this_search.rb +31 -0
- data/sunspot/lib/sunspot/search/paginated_collection.rb +57 -0
- data/sunspot/lib/sunspot/search/query_facet.rb +67 -0
- data/sunspot/lib/sunspot/search/range_facet.rb +37 -0
- data/sunspot/lib/sunspot/search/standard_search.rb +21 -0
- data/sunspot/lib/sunspot/session.rb +262 -0
- data/sunspot/lib/sunspot/session_proxy.rb +95 -0
- data/sunspot/lib/sunspot/session_proxy/abstract_session_proxy.rb +29 -0
- data/sunspot/lib/sunspot/session_proxy/class_sharding_session_proxy.rb +66 -0
- data/sunspot/lib/sunspot/session_proxy/id_sharding_session_proxy.rb +89 -0
- data/sunspot/lib/sunspot/session_proxy/master_slave_session_proxy.rb +43 -0
- data/sunspot/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb +67 -0
- data/sunspot/lib/sunspot/session_proxy/sharding_session_proxy.rb +222 -0
- data/sunspot/lib/sunspot/session_proxy/silent_fail_session_proxy.rb +42 -0
- data/sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb +37 -0
- data/sunspot/lib/sunspot/setup.rb +350 -0
- data/sunspot/lib/sunspot/text_field_setup.rb +29 -0
- data/sunspot/lib/sunspot/type.rb +393 -0
- data/sunspot/lib/sunspot/util.rb +252 -0
- data/sunspot/lib/sunspot/version.rb +3 -0
- data/sunspot/script/console +10 -0
- data/sunspot/spec/api/adapters_spec.rb +68 -0
- data/sunspot/spec/api/batcher_spec.rb +112 -0
- data/sunspot/spec/api/binding_spec.rb +50 -0
- data/sunspot/spec/api/class_set_spec.rb +24 -0
- data/sunspot/spec/api/hit_enumerable_spec.rb +47 -0
- data/sunspot/spec/api/indexer/attributes_spec.rb +149 -0
- data/sunspot/spec/api/indexer/batch_spec.rb +72 -0
- data/sunspot/spec/api/indexer/dynamic_fields_spec.rb +42 -0
- data/sunspot/spec/api/indexer/fixed_fields_spec.rb +57 -0
- data/sunspot/spec/api/indexer/fulltext_spec.rb +43 -0
- data/sunspot/spec/api/indexer/removal_spec.rb +53 -0
- data/sunspot/spec/api/indexer/spec_helper.rb +1 -0
- data/sunspot/spec/api/indexer_spec.rb +14 -0
- data/sunspot/spec/api/query/advanced_manipulation_examples.rb +35 -0
- data/sunspot/spec/api/query/connectives_examples.rb +201 -0
- data/sunspot/spec/api/query/dsl_spec.rb +18 -0
- data/sunspot/spec/api/query/dynamic_fields_examples.rb +165 -0
- data/sunspot/spec/api/query/faceting_examples.rb +497 -0
- data/sunspot/spec/api/query/fulltext_examples.rb +313 -0
- data/sunspot/spec/api/query/function_spec.rb +79 -0
- data/sunspot/spec/api/query/geo_examples.rb +68 -0
- data/sunspot/spec/api/query/group_spec.rb +32 -0
- data/sunspot/spec/api/query/highlighting_examples.rb +245 -0
- data/sunspot/spec/api/query/more_like_this_spec.rb +140 -0
- data/sunspot/spec/api/query/ordering_pagination_examples.rb +116 -0
- data/sunspot/spec/api/query/scope_examples.rb +275 -0
- data/sunspot/spec/api/query/spatial_examples.rb +27 -0
- data/sunspot/spec/api/query/spec_helper.rb +1 -0
- data/sunspot/spec/api/query/standard_spec.rb +29 -0
- data/sunspot/spec/api/query/text_field_scoping_examples.rb +30 -0
- data/sunspot/spec/api/query/types_spec.rb +20 -0
- data/sunspot/spec/api/search/dynamic_fields_spec.rb +33 -0
- data/sunspot/spec/api/search/faceting_spec.rb +360 -0
- data/sunspot/spec/api/search/highlighting_spec.rb +69 -0
- data/sunspot/spec/api/search/hits_spec.rb +147 -0
- data/sunspot/spec/api/search/paginated_collection_spec.rb +36 -0
- data/sunspot/spec/api/search/results_spec.rb +72 -0
- data/sunspot/spec/api/search/search_spec.rb +23 -0
- data/sunspot/spec/api/search/spec_helper.rb +1 -0
- data/sunspot/spec/api/session_proxy/class_sharding_session_proxy_spec.rb +85 -0
- data/sunspot/spec/api/session_proxy/id_sharding_session_proxy_spec.rb +30 -0
- data/sunspot/spec/api/session_proxy/master_slave_session_proxy_spec.rb +41 -0
- data/sunspot/spec/api/session_proxy/retry_5xx_session_proxy_spec.rb +78 -0
- data/sunspot/spec/api/session_proxy/sharding_session_proxy_spec.rb +77 -0
- data/sunspot/spec/api/session_proxy/silent_fail_session_proxy_spec.rb +24 -0
- data/sunspot/spec/api/session_proxy/spec_helper.rb +9 -0
- data/sunspot/spec/api/session_proxy/thread_local_session_proxy_spec.rb +39 -0
- data/sunspot/spec/api/session_spec.rb +232 -0
- data/sunspot/spec/api/spec_helper.rb +3 -0
- data/sunspot/spec/api/sunspot_spec.rb +29 -0
- data/sunspot/spec/ext.rb +11 -0
- data/sunspot/spec/helpers/indexer_helper.rb +17 -0
- data/sunspot/spec/helpers/integration_helper.rb +8 -0
- data/sunspot/spec/helpers/mock_session_helper.rb +13 -0
- data/sunspot/spec/helpers/query_helper.rb +26 -0
- data/sunspot/spec/helpers/search_helper.rb +68 -0
- data/sunspot/spec/integration/dynamic_fields_spec.rb +57 -0
- data/sunspot/spec/integration/faceting_spec.rb +330 -0
- data/sunspot/spec/integration/field_grouping_spec.rb +100 -0
- data/sunspot/spec/integration/geospatial_spec.rb +96 -0
- data/sunspot/spec/integration/highlighting_spec.rb +44 -0
- data/sunspot/spec/integration/indexing_spec.rb +55 -0
- data/sunspot/spec/integration/keyword_search_spec.rb +317 -0
- data/sunspot/spec/integration/local_search_spec.rb +64 -0
- data/sunspot/spec/integration/more_like_this_spec.rb +43 -0
- data/sunspot/spec/integration/scoped_search_spec.rb +386 -0
- data/sunspot/spec/integration/stored_fields_spec.rb +12 -0
- data/sunspot/spec/integration/test_pagination.rb +43 -0
- data/sunspot/spec/integration/unicode_spec.rb +15 -0
- data/sunspot/spec/mocks/adapters.rb +33 -0
- data/sunspot/spec/mocks/blog.rb +3 -0
- data/sunspot/spec/mocks/comment.rb +21 -0
- data/sunspot/spec/mocks/connection.rb +126 -0
- data/sunspot/spec/mocks/mock_adapter.rb +30 -0
- data/sunspot/spec/mocks/mock_class_sharding_session_proxy.rb +24 -0
- data/sunspot/spec/mocks/mock_record.rb +52 -0
- data/sunspot/spec/mocks/mock_sharding_session_proxy.rb +15 -0
- data/sunspot/spec/mocks/photo.rb +11 -0
- data/sunspot/spec/mocks/post.rb +86 -0
- data/sunspot/spec/mocks/super_class.rb +2 -0
- data/sunspot/spec/mocks/user.rb +13 -0
- data/sunspot/spec/spec_helper.rb +40 -0
- data/sunspot/sunspot.gemspec +37 -0
- data/sunspot/tasks/rdoc.rake +27 -0
- data/sunspot/tasks/schema.rake +19 -0
- data/{dev_tasks → sunspot/tasks}/todo.rake +0 -0
- data/sunspot_rails/.gitignore +7 -0
- data/{.rspec → sunspot_rails/.rspec} +0 -0
- data/{History.txt → sunspot_rails/History.txt} +0 -0
- data/sunspot_rails/LICENSE +18 -0
- data/{MIT-LICENSE → sunspot_rails/MIT-LICENSE} +0 -0
- data/{README.rdoc → sunspot_rails/README.rdoc} +0 -0
- data/sunspot_rails/Rakefile +17 -0
- data/{TODO → sunspot_rails/TODO} +0 -0
- data/{dev_tasks → sunspot_rails/dev_tasks}/rdoc.rake +0 -0
- data/{dev_tasks → sunspot_rails/dev_tasks}/release.rake +0 -0
- data/{dev_tasks → sunspot_rails/dev_tasks}/spec.rake +0 -0
- data/sunspot_rails/dev_tasks/todo.rake +4 -0
- data/{gemfiles → sunspot_rails/gemfiles}/rails-2.3.14 +0 -0
- data/{gemfiles → sunspot_rails/gemfiles}/rails-3.0.15 +0 -0
- data/{gemfiles → sunspot_rails/gemfiles}/rails-3.1.6 +0 -0
- data/{gemfiles → sunspot_rails/gemfiles}/rails-3.2.6 +0 -0
- data/{generators → sunspot_rails/generators}/sunspot/sunspot_generator.rb +0 -0
- data/{generators → sunspot_rails/generators}/sunspot/templates/sunspot.yml +0 -0
- data/{install.rb → sunspot_rails/install.rb} +0 -0
- data/{lib → sunspot_rails/lib}/generators/sunspot_rails.rb +0 -0
- data/{lib → sunspot_rails/lib}/generators/sunspot_rails/install/install_generator.rb +0 -0
- data/{lib → sunspot_rails/lib}/generators/sunspot_rails/install/templates/config/sunspot.yml +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/adapters.rb +5 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/configuration.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/init.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/log_subscriber.rb +12 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/railtie.rb +5 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/railties/controller_runtime.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/request_lifecycle.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/searchable.rb +10 -6
- data/{lib → sunspot_rails/lib}/sunspot/rails/server.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/solr_instrumentation.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/solr_logging.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/spec_helper.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/stub_session_proxy.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot/rails/tasks.rb +0 -0
- data/{lib → sunspot_rails/lib}/sunspot_rails.rb +0 -0
- data/{spec → sunspot_rails/spec}/configuration_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/model_lifecycle_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/model_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/controllers/application_controller.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/controllers/posts_controller.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/author.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/blog.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/location.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/photo_post.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/post.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/post_with_auto.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/app/models/post_with_default_scope.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/config/boot.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/config/preinitializer.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/config/routes.rb +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/config/sunspot.yml +0 -0
- data/{spec → sunspot_rails/spec}/rails_template/db/schema.rb +0 -0
- data/{spec → sunspot_rails/spec}/request_lifecycle_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/schema.rb +0 -0
- data/{spec → sunspot_rails/spec}/searchable_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/server_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/session_spec.rb +0 -0
- data/{spec → sunspot_rails/spec}/shared_examples/indexed_after_save.rb +0 -0
- data/{spec → sunspot_rails/spec}/shared_examples/not_indexed_after_save.rb +0 -0
- data/{spec → sunspot_rails/spec}/spec_helper.rb +0 -0
- data/{spec → sunspot_rails/spec}/stub_session_proxy_spec.rb +0 -0
- data/{sunspot_rails.gemspec → sunspot_rails/sunspot_rails.gemspec} +0 -0
- data/sunspot_solr/Gemfile +3 -0
- data/sunspot_solr/README.rdoc +24 -0
- data/sunspot_solr/bin/sunspot-installer +20 -0
- data/sunspot_solr/bin/sunspot-solr +80 -0
- data/sunspot_solr/lib/sunspot/solr/installer.rb +25 -0
- data/sunspot_solr/lib/sunspot/solr/installer/config_installer.rb +46 -0
- data/sunspot_solr/lib/sunspot/solr/installer/task_helper.rb +13 -0
- data/sunspot_solr/lib/sunspot/solr/java.rb +10 -0
- data/sunspot_solr/lib/sunspot/solr/railtie.rb +15 -0
- data/sunspot_solr/lib/sunspot/solr/server.rb +223 -0
- data/sunspot_solr/lib/sunspot/solr/tasks.rb +49 -0
- data/sunspot_solr/lib/sunspot_solr.rb +5 -0
- data/sunspot_solr/solr/README.txt +42 -0
- data/sunspot_solr/solr/etc/jetty.xml +219 -0
- data/sunspot_solr/solr/etc/webdefault.xml +379 -0
- data/sunspot_solr/solr/lib/jetty-6.1.26-patched-JETTY-1340.jar +0 -0
- data/sunspot_solr/solr/lib/jetty-util-6.1.26-patched-JETTY-1340.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/ant-1.6.5.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/core-3.1.1.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/jsp-2.1.jar +0 -0
- data/sunspot_solr/solr/lib/jsp-2.1/jsp-api-2.1.jar +0 -0
- data/sunspot_solr/solr/lib/servlet-api-2.5-20081211.jar +0 -0
- data/sunspot_solr/solr/solr/.gitignore +1 -0
- data/sunspot_solr/solr/solr/README.txt +54 -0
- data/sunspot_solr/solr/solr/conf/admin-extra.html +31 -0
- data/sunspot_solr/solr/solr/conf/elevate.xml +36 -0
- data/sunspot_solr/solr/solr/conf/mapping-ISOLatin1Accent.txt +246 -0
- data/sunspot_solr/solr/solr/conf/protwords.txt +21 -0
- data/sunspot_solr/solr/solr/conf/schema.xml +250 -0
- data/sunspot_solr/solr/solr/conf/scripts.conf +24 -0
- data/sunspot_solr/solr/solr/conf/solrconfig.xml +934 -0
- data/sunspot_solr/solr/solr/conf/spellings.txt +2 -0
- data/sunspot_solr/solr/solr/conf/stopwords.txt +58 -0
- data/sunspot_solr/solr/solr/conf/synonyms.txt +31 -0
- data/sunspot_solr/solr/solr/conf/xslt/example.xsl +132 -0
- data/sunspot_solr/solr/solr/conf/xslt/example_atom.xsl +67 -0
- data/sunspot_solr/solr/solr/conf/xslt/example_rss.xsl +66 -0
- data/sunspot_solr/solr/solr/conf/xslt/luke.xsl +337 -0
- data/sunspot_solr/solr/start.jar +0 -0
- data/sunspot_solr/solr/webapps/solr.war +0 -0
- data/sunspot_solr/spec/server_spec.rb +98 -0
- data/sunspot_solr/spec/spec_helper.rb +18 -0
- data/sunspot_solr/sunspot_solr.gemspec +37 -0
- data/tools/gem_tasks.rb +69 -0
- metadata +356 -177
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'solr', 'installer')
|
5
|
+
|
6
|
+
home = ARGV.select { |arg| arg !~ /^-/ }.last || File.join(Dir.pwd, "solr")
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: sunspot-installer [options] [solr-home]"
|
11
|
+
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
12
|
+
options[:verbose] = v
|
13
|
+
end
|
14
|
+
opts.on('-f', '--[no-]force', 'Overwrite schema and solrconfig files with Sunspot default, instead of modifying them (recommended for new Solr installation)') do |f|
|
15
|
+
options[:force] = f
|
16
|
+
end
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
Sunspot::Solr::Installer.execute(home, options)
|
20
|
+
puts "Installed to #{home}"
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
begin
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'tmpdir'
|
6
|
+
require 'optparse'
|
7
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'sunspot', 'solr', 'server')
|
8
|
+
rescue LoadError => e
|
9
|
+
if require 'rubygems'
|
10
|
+
retry
|
11
|
+
else
|
12
|
+
raise(e)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
server = Sunspot::Solr::Server.new
|
17
|
+
|
18
|
+
opts = OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: sunspot-solr (start|stop|run) [options]"
|
20
|
+
|
21
|
+
opts.on '-p', '--port=PORT', 'Port on which to run Solr (default 8983)' do |p|
|
22
|
+
server.port = p
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on '-b', '--bind-address=address', 'Interface on which to run Solr (default 0.0.0.0)' do |b|
|
26
|
+
server.bind_address = b
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on '-d', '--data-directory=DIRECTORY', 'Solr data directory' do |d|
|
30
|
+
server.solr_data_dir = File.expand_path(d)
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on '-s', '--solr-home=HOME', 'Solr home directory (should contain conf/ directory)' do |s|
|
34
|
+
server.solr_home = File.expand_path(s)
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on '-j', '--solr-jar=JAR', 'Solr start jar' do |j|
|
38
|
+
server.solr_jar = File.expand_path(j)
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on '--pid-dir=PID_DIR', 'Directory for pid files' do |pd|
|
42
|
+
server.pid_dir = File.expand_path(pd)
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on '-l', '--log-level=LOG_LEVEL', 'Solr logging level' do |l|
|
46
|
+
server.log_level = l
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on '--log-file=LOG_FILE', 'Path to Solr log file' do |lf|
|
50
|
+
server.log_file = File.expand_path(lf)
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on '--max-memory=MEMORY', 'Specify the maximum size of the memory allocation pool' do |mm|
|
54
|
+
server.max_memory = mm
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on '--min-memory=MEMORY', 'Specify the initial size of the memory allocation pool' do |mm|
|
58
|
+
server.min_memory = mm
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
opts.parse!
|
63
|
+
|
64
|
+
begin
|
65
|
+
case ARGV[0]
|
66
|
+
when 'start'
|
67
|
+
server.start
|
68
|
+
when 'run'
|
69
|
+
server.run
|
70
|
+
when 'stop'
|
71
|
+
server.stop
|
72
|
+
when 'restart'
|
73
|
+
server.stop
|
74
|
+
server.start
|
75
|
+
else
|
76
|
+
abort(opts.help)
|
77
|
+
end
|
78
|
+
rescue Sunspot::Solr::Server::ServerError => e
|
79
|
+
abort(e.message)
|
80
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
%w(task_helper config_installer).each do |file|
|
2
|
+
require File.join(File.dirname(__FILE__), 'installer', file)
|
3
|
+
end
|
4
|
+
|
5
|
+
module Sunspot
|
6
|
+
module Solr
|
7
|
+
class Installer
|
8
|
+
class <<self
|
9
|
+
def execute(solr_home, options = {})
|
10
|
+
new(solr_home, options).execute
|
11
|
+
end
|
12
|
+
|
13
|
+
private :new
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(solr_home, options)
|
17
|
+
@solr_home, @options = solr_home, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute
|
21
|
+
ConfigInstaller.execute(File.join(@solr_home, 'conf'), @options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module Sunspot
|
4
|
+
module Solr
|
5
|
+
class Installer
|
6
|
+
class ConfigInstaller
|
7
|
+
include TaskHelper
|
8
|
+
|
9
|
+
class <<self
|
10
|
+
def execute(config_path, options = {})
|
11
|
+
new(config_path, options).execute
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(config_path, options)
|
16
|
+
@config_path = config_path
|
17
|
+
@verbose = !!options[:verbose]
|
18
|
+
@force = !!options[:force]
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute
|
22
|
+
sunspot_config_path = File.join(File.dirname(__FILE__), '..', '..',
|
23
|
+
'..', '..', 'solr', 'solr', 'conf')
|
24
|
+
return if File.expand_path(sunspot_config_path) == File.expand_path(@config_path)
|
25
|
+
|
26
|
+
FileUtils.mkdir_p(@config_path)
|
27
|
+
Dir.glob(File.join(sunspot_config_path, '*.*')).each do |file|
|
28
|
+
file = File.expand_path(file)
|
29
|
+
dest = File.join(@config_path, File.basename(file))
|
30
|
+
|
31
|
+
if File.exist?(dest)
|
32
|
+
if @force
|
33
|
+
say("Removing existing file #{dest}")
|
34
|
+
else
|
35
|
+
next
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
say("Copying #{file} => #{dest}")
|
40
|
+
FileUtils.cp(file, dest)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'sunspot/solr/java'
|
4
|
+
require 'sunspot/solr/installer'
|
5
|
+
|
6
|
+
module Sunspot
|
7
|
+
module Solr
|
8
|
+
class Server #:nodoc:
|
9
|
+
# Raised if #stop is called but the server is not running
|
10
|
+
ServerError = Class.new(RuntimeError)
|
11
|
+
AlreadyRunningError = Class.new(ServerError)
|
12
|
+
NotRunningError = Class.new(ServerError)
|
13
|
+
JavaMissing = Class.new(ServerError)
|
14
|
+
|
15
|
+
# Name of the sunspot executable (shell script)
|
16
|
+
SOLR_START_JAR = File.expand_path(
|
17
|
+
File.join(File.dirname(__FILE__), '..', '..', '..', 'solr', 'start.jar')
|
18
|
+
)
|
19
|
+
|
20
|
+
LOG_LEVELS = Set['SEVERE', 'WARNING', 'INFO', 'CONFIG', 'FINE', 'FINER', 'FINEST']
|
21
|
+
|
22
|
+
attr_accessor :min_memory, :max_memory, :bind_address, :port, :solr_data_dir, :solr_home, :log_file
|
23
|
+
attr_writer :pid_dir, :pid_file, :log_level, :solr_data_dir, :solr_home, :solr_jar
|
24
|
+
|
25
|
+
def initialize(*args)
|
26
|
+
ensure_java_installed
|
27
|
+
super(*args)
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Bootstrap a new solr_home by creating all required
|
32
|
+
# directories.
|
33
|
+
#
|
34
|
+
# ==== Returns
|
35
|
+
#
|
36
|
+
# Boolean:: success
|
37
|
+
#
|
38
|
+
def bootstrap
|
39
|
+
unless @bootstrapped
|
40
|
+
install_solr_home
|
41
|
+
create_solr_directories
|
42
|
+
@bootstrapped = true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Start the sunspot-solr server. Bootstrap solr_home first,
|
48
|
+
# if neccessary.
|
49
|
+
#
|
50
|
+
# ==== Returns
|
51
|
+
#
|
52
|
+
# Boolean:: success
|
53
|
+
#
|
54
|
+
def start
|
55
|
+
bootstrap
|
56
|
+
|
57
|
+
if File.exist?(pid_path)
|
58
|
+
existing_pid = IO.read(pid_path).to_i
|
59
|
+
begin
|
60
|
+
Process.kill(0, existing_pid)
|
61
|
+
raise(AlreadyRunningError, "Server is already running with PID #{existing_pid}")
|
62
|
+
rescue Errno::ESRCH
|
63
|
+
STDERR.puts("Removing stale PID file at #{pid_path}")
|
64
|
+
FileUtils.rm(pid_path)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
fork do
|
68
|
+
pid = fork do
|
69
|
+
Process.setsid
|
70
|
+
STDIN.reopen('/dev/null')
|
71
|
+
STDOUT.reopen('/dev/null', 'a')
|
72
|
+
STDERR.reopen(STDOUT)
|
73
|
+
run
|
74
|
+
end
|
75
|
+
FileUtils.mkdir_p(pid_dir)
|
76
|
+
File.open(pid_path, 'w') do |file|
|
77
|
+
file << pid
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Run the sunspot-solr server in the foreground. Boostrap
|
84
|
+
# solr_home first, if neccessary.
|
85
|
+
#
|
86
|
+
# ==== Returns
|
87
|
+
#
|
88
|
+
# Boolean:: success
|
89
|
+
#
|
90
|
+
def run
|
91
|
+
bootstrap
|
92
|
+
|
93
|
+
command = ['java']
|
94
|
+
command << "-Xms#{min_memory}" if min_memory
|
95
|
+
command << "-Xmx#{max_memory}" if max_memory
|
96
|
+
command << "-Djetty.port=#{port}" if port
|
97
|
+
command << "-Djetty.host=#{bind_address}" if bind_address
|
98
|
+
command << "-Dsolr.data.dir=#{solr_data_dir}" if solr_data_dir
|
99
|
+
command << "-Dsolr.solr.home=#{solr_home}" if solr_home
|
100
|
+
command << "-Djava.util.logging.config.file=#{logging_config_path}" if logging_config_path
|
101
|
+
command << '-jar' << File.basename(solr_jar)
|
102
|
+
FileUtils.cd(File.dirname(solr_jar)) do
|
103
|
+
exec(*command)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Stop the sunspot-solr server.
|
109
|
+
#
|
110
|
+
# ==== Returns
|
111
|
+
#
|
112
|
+
# Boolean:: success
|
113
|
+
#
|
114
|
+
def stop
|
115
|
+
if File.exist?(pid_path)
|
116
|
+
pid = IO.read(pid_path).to_i
|
117
|
+
begin
|
118
|
+
Process.kill('TERM', pid)
|
119
|
+
rescue Errno::ESRCH
|
120
|
+
raise NotRunningError, "Process with PID #{pid} is no longer running"
|
121
|
+
ensure
|
122
|
+
FileUtils.rm(pid_path)
|
123
|
+
end
|
124
|
+
else
|
125
|
+
raise NotRunningError, "No PID file at #{pid_path}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def log_level=(level)
|
130
|
+
unless LOG_LEVELS.include?(level.to_s.upcase)
|
131
|
+
raise(ArgumentError, "#{level} is not a valid log level: Use one of #{LOG_LEVELS.to_a.join(',')}")
|
132
|
+
end
|
133
|
+
@log_level = level.to_s.upcase
|
134
|
+
end
|
135
|
+
|
136
|
+
def log_level
|
137
|
+
@log_level || 'WARNING'
|
138
|
+
end
|
139
|
+
|
140
|
+
def pid_path
|
141
|
+
File.join(pid_dir, pid_file)
|
142
|
+
end
|
143
|
+
|
144
|
+
def pid_file
|
145
|
+
@pid_file || 'sunspot-solr.pid'
|
146
|
+
end
|
147
|
+
|
148
|
+
def pid_dir
|
149
|
+
File.expand_path(@pid_dir || FileUtils.pwd)
|
150
|
+
end
|
151
|
+
|
152
|
+
def solr_data_dir
|
153
|
+
File.expand_path(@solr_data_dir || Dir.tmpdir)
|
154
|
+
end
|
155
|
+
|
156
|
+
def solr_home
|
157
|
+
File.expand_path(@solr_home || File.join(File.dirname(solr_jar), 'solr'))
|
158
|
+
end
|
159
|
+
|
160
|
+
def solr_jar
|
161
|
+
@solr_jar || SOLR_START_JAR
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Copy default solr configuration files from sunspot
|
166
|
+
# gem to the new solr_home/config directory
|
167
|
+
#
|
168
|
+
# ==== Returns
|
169
|
+
#
|
170
|
+
# Boolean:: success
|
171
|
+
#
|
172
|
+
def install_solr_home
|
173
|
+
unless File.exists?(solr_home)
|
174
|
+
Sunspot::Solr::Installer.execute(
|
175
|
+
solr_home,
|
176
|
+
:force => true,
|
177
|
+
:verbose => true
|
178
|
+
)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
#
|
183
|
+
# Create new solr_home, config, log and pid directories
|
184
|
+
#
|
185
|
+
# ==== Returns
|
186
|
+
#
|
187
|
+
# Boolean:: success
|
188
|
+
#
|
189
|
+
def create_solr_directories
|
190
|
+
[solr_data_dir, pid_dir].each do |path|
|
191
|
+
FileUtils.mkdir_p(path) unless File.exists?(path)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
private
|
196
|
+
|
197
|
+
def ensure_java_installed
|
198
|
+
unless defined?(@java_installed)
|
199
|
+
@java_installed = Sunspot::Solr::Java.installed?
|
200
|
+
unless @java_installed
|
201
|
+
raise JavaMissing.new("You need a Java Runtime Environment to run the Solr server")
|
202
|
+
end
|
203
|
+
end
|
204
|
+
@java_installed
|
205
|
+
end
|
206
|
+
|
207
|
+
def logging_config_path
|
208
|
+
return @logging_config_path if defined?(@logging_config_path)
|
209
|
+
@logging_config_path =
|
210
|
+
if log_file
|
211
|
+
logging_config = Tempfile.new('logging.properties')
|
212
|
+
logging_config.puts("handlers = java.util.logging.FileHandler")
|
213
|
+
logging_config.puts("java.util.logging.FileHandler.level = #{log_level.to_s.upcase}")
|
214
|
+
logging_config.puts("java.util.logging.FileHandler.pattern = #{log_file}")
|
215
|
+
logging_config.puts("java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter")
|
216
|
+
logging_config.flush
|
217
|
+
logging_config.close
|
218
|
+
logging_config.path
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
namespace :sunspot do
|
2
|
+
namespace :solr do
|
3
|
+
desc 'Start the Solr instance'
|
4
|
+
task :start => :environment do
|
5
|
+
case RUBY_PLATFORM
|
6
|
+
when /w(in)?32$/, /java$/
|
7
|
+
abort("This command is not supported on #{RUBY_PLATFORM}. " +
|
8
|
+
"Use rake sunspot:solr:run to run Solr in the foreground.")
|
9
|
+
end
|
10
|
+
|
11
|
+
if defined?(Sunspot::Rails::Server)
|
12
|
+
Sunspot::Rails::Server.new.start
|
13
|
+
else
|
14
|
+
Sunspot::Solr::Server.new.start
|
15
|
+
end
|
16
|
+
|
17
|
+
puts "Successfully started Solr ..."
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Run the Solr instance in the foreground'
|
21
|
+
task :run => :environment do
|
22
|
+
if defined?(Sunspot::Rails::Server)
|
23
|
+
Sunspot::Rails::Server.new.run
|
24
|
+
else
|
25
|
+
Sunspot::Solr::Server.new.run
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Stop the Solr instance'
|
30
|
+
task :stop => :environment do
|
31
|
+
case RUBY_PLATFORM
|
32
|
+
when /w(in)?32$/, /java$/
|
33
|
+
abort("This command is not supported on #{RUBY_PLATFORM}. " +
|
34
|
+
"Use rake sunspot:solr:run to run Solr in the foreground.")
|
35
|
+
end
|
36
|
+
|
37
|
+
if defined?(Sunspot::Rails::Server)
|
38
|
+
Sunspot::Rails::Server.new.stop
|
39
|
+
else
|
40
|
+
Sunspot::Solr::Server.new.stop
|
41
|
+
end
|
42
|
+
|
43
|
+
puts "Successfully stopped Solr ..."
|
44
|
+
end
|
45
|
+
|
46
|
+
# for backwards compatibility
|
47
|
+
task :reindex => :"sunspot:reindex"
|
48
|
+
end
|
49
|
+
end
|