pduey-sunspot_rails 1.2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/History.txt +54 -0
- data/LICENSE +18 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +282 -0
- data/Rakefile +18 -0
- data/TESTING.md +35 -0
- data/TODO +8 -0
- data/VERSION.yml +4 -0
- data/dev_tasks/rdoc.rake +24 -0
- data/dev_tasks/release.rake +4 -0
- data/dev_tasks/spec.rake +27 -0
- data/dev_tasks/todo.rake +4 -0
- data/generators/sunspot/sunspot_generator.rb +9 -0
- data/generators/sunspot/templates/sunspot.yml +18 -0
- data/install.rb +1 -0
- data/lib/generators/sunspot_rails.rb +9 -0
- data/lib/generators/sunspot_rails/install/install_generator.rb +13 -0
- data/lib/generators/sunspot_rails/install/templates/config/sunspot.yml +17 -0
- data/lib/sunspot/rails.rb +63 -0
- data/lib/sunspot/rails/adapters.rb +83 -0
- data/lib/sunspot/rails/configuration.rb +323 -0
- data/lib/sunspot/rails/init.rb +5 -0
- data/lib/sunspot/rails/log_subscriber.rb +33 -0
- data/lib/sunspot/rails/railtie.rb +36 -0
- data/lib/sunspot/rails/railties/controller_runtime.rb +36 -0
- data/lib/sunspot/rails/request_lifecycle.rb +36 -0
- data/lib/sunspot/rails/searchable.rb +420 -0
- data/lib/sunspot/rails/server.rb +173 -0
- data/lib/sunspot/rails/solr_instrumentation.rb +20 -0
- data/lib/sunspot/rails/solr_logging.rb +62 -0
- data/lib/sunspot/rails/spec_helper.rb +26 -0
- data/lib/sunspot/rails/stub_session_proxy.rb +142 -0
- data/lib/sunspot/rails/tasks.rb +66 -0
- data/lib/sunspot_rails.rb +12 -0
- data/spec/configuration_spec.rb +173 -0
- data/spec/model_lifecycle_spec.rb +63 -0
- data/spec/model_spec.rb +478 -0
- data/spec/rails2/.gitignore +2 -0
- data/spec/rails2/Gemfile +15 -0
- data/spec/rails2/Rakefile +17 -0
- data/spec/rails2/app/controllers/application.rb +10 -0
- data/spec/rails2/app/controllers/application_controller.rb +10 -0
- data/spec/rails2/app/controllers/posts_controller.rb +6 -0
- data/spec/rails2/app/models/author.rb +8 -0
- data/spec/rails2/app/models/blog.rb +12 -0
- data/spec/rails2/app/models/location.rb +2 -0
- data/spec/rails2/app/models/photo_post.rb +2 -0
- data/spec/rails2/app/models/post.rb +11 -0
- data/spec/rails2/app/models/post_with_auto.rb +10 -0
- data/spec/rails2/app/models/post_with_conditional_index.rb +13 -0
- data/spec/rails2/app/models/post_with_default_scope.rb +11 -0
- data/spec/rails2/config/boot.rb +116 -0
- data/spec/rails2/config/database.yml +4 -0
- data/spec/rails2/config/environment.rb +41 -0
- data/spec/rails2/config/environments/development.rb +27 -0
- data/spec/rails2/config/environments/test.rb +27 -0
- data/spec/rails2/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/rails2/config/initializers/session_store.rb +15 -0
- data/spec/rails2/config/preinitializer.rb +19 -0
- data/spec/rails2/config/routes.rb +43 -0
- data/spec/rails2/config/sunspot.yml +19 -0
- data/spec/rails2/db/schema.rb +27 -0
- data/spec/rails2/script/console +3 -0
- data/spec/rails3/.gitignore +4 -0
- data/spec/rails3/Gemfile +15 -0
- data/spec/rails3/README +281 -0
- data/spec/rails3/Rakefile +7 -0
- data/spec/rails3/app/controllers/application.rb +4 -0
- data/spec/rails3/app/controllers/application_controller.rb +4 -0
- data/spec/rails3/app/controllers/posts_controller.rb +6 -0
- data/spec/rails3/app/models/author.rb +8 -0
- data/spec/rails3/app/models/blog.rb +12 -0
- data/spec/rails3/app/models/location.rb +2 -0
- data/spec/rails3/app/models/photo_post.rb +2 -0
- data/spec/rails3/app/models/post.rb +11 -0
- data/spec/rails3/app/models/post_with_auto.rb +10 -0
- data/spec/rails3/app/models/post_with_conditional_index.rb +13 -0
- data/spec/rails3/app/models/post_with_default_scope.rb +11 -0
- data/spec/rails3/config.ru +4 -0
- data/spec/rails3/config/application.rb +46 -0
- data/spec/rails3/config/boot.rb +13 -0
- data/spec/rails3/config/database.yml +22 -0
- data/spec/rails3/config/environment.rb +5 -0
- data/spec/rails3/config/environments/development.rb +19 -0
- data/spec/rails3/config/environments/test.rb +19 -0
- data/spec/rails3/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/rails3/config/initializers/inflections.rb +10 -0
- data/spec/rails3/config/initializers/mime_types.rb +5 -0
- data/spec/rails3/config/initializers/new_rails_defaults.rb +19 -0
- data/spec/rails3/config/initializers/secret_token.rb +7 -0
- data/spec/rails3/config/initializers/session_store.rb +8 -0
- data/spec/rails3/config/locales/en.yml +5 -0
- data/spec/rails3/config/routes.rb +59 -0
- data/spec/rails3/config/sunspot.yml +19 -0
- data/spec/rails3/db/schema.rb +27 -0
- data/spec/rails3/script/console +3 -0
- data/spec/rails3/script/rails +6 -0
- data/spec/rails3/solr/.gitignore +1 -0
- data/spec/rails3/solr/conf/elevate.xml +36 -0
- data/spec/rails3/solr/conf/schema.xml +238 -0
- data/spec/rails3/solr/conf/solrconfig.xml +938 -0
- data/spec/rails3/solr/conf/spellings.txt +2 -0
- data/spec/rails3/solr/conf/stopwords.txt +58 -0
- data/spec/rails3/solr/conf/synonyms.txt +31 -0
- data/spec/rails3/solr/lib/lucene-spatial-2.9.1.jar +0 -0
- data/spec/rails3/solr/lib/solr-spatial-light-0.0.6.jar +0 -0
- data/spec/request_lifecycle_spec.rb +61 -0
- data/spec/schema.rb +27 -0
- data/spec/server_spec.rb +37 -0
- data/spec/session_spec.rb +24 -0
- data/spec/spec_helper.rb +46 -0
- data/spec/stub_session_proxy_spec.rb +122 -0
- data/sunspot_rails.gemspec +44 -0
- metadata +322 -0
data/VERSION.yml
ADDED
data/dev_tasks/rdoc.rake
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'hanna/rdoctask'
|
3
|
+
rescue LoadError
|
4
|
+
if require 'rubygems'
|
5
|
+
retry
|
6
|
+
end
|
7
|
+
# It's OK if hanna isn't installed.
|
8
|
+
end
|
9
|
+
|
10
|
+
Rake::RDocTask.new(:doc) do |rdoc|
|
11
|
+
rdoc.main = 'README.rdoc'
|
12
|
+
rdoc.rdoc_files.include('README.rdoc', 'lib/sunspot/rails/**/*.rb', 'lib/sunspot/rails.rb')
|
13
|
+
rdoc.rdoc_dir = 'doc'
|
14
|
+
end
|
15
|
+
|
16
|
+
namespace :doc do
|
17
|
+
desc 'Generate rdoc and move into pages directory'
|
18
|
+
task :publish => :redoc do
|
19
|
+
doc_dir = File.join(File.dirname(__FILE__), '..', 'doc')
|
20
|
+
publish_dir = File.join(File.dirname(__FILE__), '..', '..', 'pages', 'rails', 'docs')
|
21
|
+
FileUtils.rm_rf(publish_dir) if File.exist?(publish_dir)
|
22
|
+
FileUtils.cp_r(doc_dir, publish_dir)
|
23
|
+
end
|
24
|
+
end
|
data/dev_tasks/spec.rake
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
desc 'Run spec suite in both Rails 2 and Rails 3'
|
2
|
+
task :spec => [:"spec:rails2", :"spec:rails3"]
|
3
|
+
|
4
|
+
namespace :spec do
|
5
|
+
desc 'Run spec suite in Rails 2 application'
|
6
|
+
task :rails2 do
|
7
|
+
puts "Running specs for Rails 2"
|
8
|
+
ENV['BUNDLE_GEMFILE'] = 'spec/rails2/Gemfile'
|
9
|
+
ENV['RAILS_ROOT'] = 'spec/rails2'
|
10
|
+
require 'bundler'
|
11
|
+
Bundler.setup(:default, :test)
|
12
|
+
# success = system "spec --color #{ENV['SPEC'] || 'spec'}"
|
13
|
+
success = system "spec spec/*_spec.rb --color"
|
14
|
+
exit(success ? 0 : 1)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run spec suite in Rails 3 application'
|
18
|
+
task :rails3 do
|
19
|
+
puts "Running specs for Rails 3"
|
20
|
+
ENV['BUNDLE_GEMFILE'] = 'spec/rails3/Gemfile'
|
21
|
+
ENV['RAILS_ROOT'] = 'spec/rails3'
|
22
|
+
require 'bundler'
|
23
|
+
Bundler.setup(:default, :test)
|
24
|
+
success = system "rspec #{ENV['SPEC'] || 'spec/*_spec.rb'} --color"
|
25
|
+
exit(success ? 0 : 1)
|
26
|
+
end
|
27
|
+
end
|
data/dev_tasks/todo.rake
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SunspotRails
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
def self.source_root
|
5
|
+
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
6
|
+
end
|
7
|
+
def copy_config_file
|
8
|
+
template 'config/sunspot.yml'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'sunspot'
|
2
|
+
require File.join(File.dirname(__FILE__), 'rails', 'configuration')
|
3
|
+
require File.join(File.dirname(__FILE__), 'rails', 'adapters')
|
4
|
+
require File.join(File.dirname(__FILE__), 'rails', 'request_lifecycle')
|
5
|
+
require File.join(File.dirname(__FILE__), 'rails', 'searchable')
|
6
|
+
|
7
|
+
module Sunspot #:nodoc:
|
8
|
+
module Rails #:nodoc:
|
9
|
+
autoload :SolrInstrumentation, File.join(File.dirname(__FILE__), 'rails', 'solr_instrumentation')
|
10
|
+
autoload :StubSessionProxy, File.join(File.dirname(__FILE__), 'rails', 'stub_session_proxy')
|
11
|
+
begin
|
12
|
+
require 'sunspot_solr'
|
13
|
+
autoload :Server, File.join(File.dirname(__FILE__), 'rails', 'server')
|
14
|
+
rescue LoadError => e
|
15
|
+
# We're fine
|
16
|
+
end
|
17
|
+
|
18
|
+
class <<self
|
19
|
+
attr_writer :configuration
|
20
|
+
|
21
|
+
def configuration
|
22
|
+
@configuration ||= Sunspot::Rails::Configuration.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset
|
26
|
+
@configuration = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_session(configuration = self.configuration)
|
30
|
+
if configuration.has_master?
|
31
|
+
SessionProxy::MasterSlaveSessionProxy.new(
|
32
|
+
SessionProxy::ThreadLocalSessionProxy.new(master_config(configuration)),
|
33
|
+
SessionProxy::ThreadLocalSessionProxy.new(slave_config(configuration))
|
34
|
+
)
|
35
|
+
else
|
36
|
+
SessionProxy::ThreadLocalSessionProxy.new(slave_config(configuration))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def master_config(sunspot_rails_configuration)
|
43
|
+
config = Sunspot::Configuration.build
|
44
|
+
config.solr.url = URI::HTTP.build(
|
45
|
+
:host => sunspot_rails_configuration.master_hostname,
|
46
|
+
:port => sunspot_rails_configuration.master_port,
|
47
|
+
:path => sunspot_rails_configuration.master_path
|
48
|
+
).to_s
|
49
|
+
config
|
50
|
+
end
|
51
|
+
|
52
|
+
def slave_config(sunspot_rails_configuration)
|
53
|
+
config = Sunspot::Configuration.build
|
54
|
+
config.solr.url = URI::HTTP.build(
|
55
|
+
:host => sunspot_rails_configuration.hostname,
|
56
|
+
:port => sunspot_rails_configuration.port,
|
57
|
+
:path => sunspot_rails_configuration.path
|
58
|
+
).to_s
|
59
|
+
config
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Sunspot #:nodoc:
|
2
|
+
module Rails #:nodoc:
|
3
|
+
#
|
4
|
+
# This module provides Sunspot Adapter implementations for ActiveRecord
|
5
|
+
# models.
|
6
|
+
#
|
7
|
+
module Adapters
|
8
|
+
class ActiveRecordInstanceAdapter < Sunspot::Adapters::InstanceAdapter
|
9
|
+
#
|
10
|
+
# Return the primary key for the adapted instance
|
11
|
+
#
|
12
|
+
# ==== Returns
|
13
|
+
#
|
14
|
+
# Integer:: Database ID of model
|
15
|
+
#
|
16
|
+
def id
|
17
|
+
@instance.id
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class ActiveRecordDataAccessor < Sunspot::Adapters::DataAccessor
|
22
|
+
# options for the find
|
23
|
+
attr_accessor :include, :select
|
24
|
+
|
25
|
+
#
|
26
|
+
# Set the fields to select from the database. This will be passed
|
27
|
+
# to ActiveRecord.
|
28
|
+
#
|
29
|
+
# ==== Parameters
|
30
|
+
#
|
31
|
+
# value<Mixed>:: String of comma-separated columns or array of columns
|
32
|
+
#
|
33
|
+
def select=(value)
|
34
|
+
value = value.join(', ') if value.respond_to?(:join)
|
35
|
+
@select = value
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Get one ActiveRecord instance out of the database by ID
|
40
|
+
#
|
41
|
+
# ==== Parameters
|
42
|
+
#
|
43
|
+
# id<String>:: Database ID of model to retreive
|
44
|
+
#
|
45
|
+
# ==== Returns
|
46
|
+
#
|
47
|
+
# ActiveRecord::Base:: ActiveRecord model
|
48
|
+
#
|
49
|
+
def load(id)
|
50
|
+
@clazz.first(options_for_find.merge(
|
51
|
+
:conditions => { @clazz.primary_key => id}
|
52
|
+
))
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Get a collection of ActiveRecord instances out of the database by ID
|
57
|
+
#
|
58
|
+
# ==== Parameters
|
59
|
+
#
|
60
|
+
# ids<Array>:: Database IDs of models to retrieve
|
61
|
+
#
|
62
|
+
# ==== Returns
|
63
|
+
#
|
64
|
+
# Array:: Collection of ActiveRecord models
|
65
|
+
#
|
66
|
+
def load_all(ids)
|
67
|
+
@clazz.all(options_for_find.merge(
|
68
|
+
:conditions => { @clazz.primary_key => ids.map { |id| id }}
|
69
|
+
))
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
|
74
|
+
def options_for_find
|
75
|
+
options = {}
|
76
|
+
options[:include] = @include unless @include.blank?
|
77
|
+
options[:select] = @select unless @select.blank?
|
78
|
+
options
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,323 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Sunspot #:nodoc:
|
4
|
+
module Rails #:nodoc:
|
5
|
+
#
|
6
|
+
# Sunspot::Rails is configured via the config/sunspot.yml file, which
|
7
|
+
# contains properties keyed by environment name. A sample sunspot.yml file
|
8
|
+
# would look like:
|
9
|
+
#
|
10
|
+
# development:
|
11
|
+
# solr:
|
12
|
+
# hostname: localhost
|
13
|
+
# port: 8982
|
14
|
+
# min_memory: 512M
|
15
|
+
# max_memory: 1G
|
16
|
+
# solr_jar: /some/path/solr15/start.jar
|
17
|
+
# test:
|
18
|
+
# solr:
|
19
|
+
# hostname: localhost
|
20
|
+
# port: 8983
|
21
|
+
# log_level: OFF
|
22
|
+
# production:
|
23
|
+
# solr:
|
24
|
+
# hostname: localhost
|
25
|
+
# port: 8983
|
26
|
+
# path: /solr/myindex
|
27
|
+
# log_level: WARNING
|
28
|
+
# solr_home: /some/path
|
29
|
+
# master_solr:
|
30
|
+
# hostname: localhost
|
31
|
+
# port: 8982
|
32
|
+
# path: /solr
|
33
|
+
# auto_commit_after_request: true
|
34
|
+
#
|
35
|
+
# Sunspot::Rails uses the configuration to set up the Solr connection, as
|
36
|
+
# well as for starting Solr with the appropriate port using the
|
37
|
+
# <code>rake sunspot:solr:start</code> task.
|
38
|
+
#
|
39
|
+
# If the <code>master_solr</code> configuration is present, Sunspot will use
|
40
|
+
# the Solr instance specified here for all write operations, and the Solr
|
41
|
+
# configured under <code>solr</code> for all read operations.
|
42
|
+
#
|
43
|
+
class Configuration
|
44
|
+
attr_writer :user_configuration
|
45
|
+
#
|
46
|
+
# The host name at which to connect to Solr. Default 'localhost'.
|
47
|
+
#
|
48
|
+
# ==== Returns
|
49
|
+
#
|
50
|
+
# String:: host name
|
51
|
+
#
|
52
|
+
def hostname
|
53
|
+
unless defined?(@hostname)
|
54
|
+
@hostname = solr_url.host if solr_url
|
55
|
+
@hostname ||= user_configuration_from_key('solr', 'hostname')
|
56
|
+
@hostname ||= default_hostname
|
57
|
+
end
|
58
|
+
@hostname
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# The port at which to connect to Solr.
|
63
|
+
# Defaults to 8981 in test, 8982 in development and 8983 in production.
|
64
|
+
#
|
65
|
+
# ==== Returns
|
66
|
+
#
|
67
|
+
# Integer:: port
|
68
|
+
#
|
69
|
+
def port
|
70
|
+
unless defined?(@port)
|
71
|
+
@port = solr_url.port if solr_url
|
72
|
+
@port ||= user_configuration_from_key('solr', 'port')
|
73
|
+
@port ||= default_port
|
74
|
+
@port = @port.to_i
|
75
|
+
end
|
76
|
+
@port
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# The url path to the Solr servlet (useful if you are running multicore).
|
81
|
+
# Default '/solr'.
|
82
|
+
#
|
83
|
+
# ==== Returns
|
84
|
+
#
|
85
|
+
# String:: path
|
86
|
+
#
|
87
|
+
def path
|
88
|
+
unless defined?(@path)
|
89
|
+
@path = solr_url.path if solr_url
|
90
|
+
@path ||= user_configuration_from_key('solr', 'path')
|
91
|
+
@path ||= default_path
|
92
|
+
end
|
93
|
+
@path
|
94
|
+
end
|
95
|
+
|
96
|
+
#
|
97
|
+
# The host name at which to connect to the master Solr instance. Defaults
|
98
|
+
# to the 'hostname' configuration option.
|
99
|
+
#
|
100
|
+
# ==== Returns
|
101
|
+
#
|
102
|
+
# String:: host name
|
103
|
+
#
|
104
|
+
def master_hostname
|
105
|
+
@master_hostname ||= (user_configuration_from_key('master_solr', 'hostname') || hostname)
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# The port at which to connect to the master Solr instance. Defaults to
|
110
|
+
# the 'port' configuration option.
|
111
|
+
#
|
112
|
+
# ==== Returns
|
113
|
+
#
|
114
|
+
# Integer:: port
|
115
|
+
#
|
116
|
+
def master_port
|
117
|
+
@master_port ||= (user_configuration_from_key('master_solr', 'port') || port).to_i
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
121
|
+
# The path to the master Solr servlet (useful if you are running multicore).
|
122
|
+
# Defaults to the value of the 'path' configuration option.
|
123
|
+
#
|
124
|
+
# ==== Returns
|
125
|
+
#
|
126
|
+
# String:: path
|
127
|
+
#
|
128
|
+
def master_path
|
129
|
+
@master_path ||= (user_configuration_from_key('master_solr', 'path') || path)
|
130
|
+
end
|
131
|
+
|
132
|
+
#
|
133
|
+
# True if there is a master Solr instance configured, otherwise false.
|
134
|
+
#
|
135
|
+
# ==== Returns
|
136
|
+
#
|
137
|
+
# Boolean:: bool
|
138
|
+
#
|
139
|
+
def has_master?
|
140
|
+
@has_master = !!user_configuration_from_key('master_solr')
|
141
|
+
end
|
142
|
+
|
143
|
+
#
|
144
|
+
# The default log_level that should be passed to solr. You can
|
145
|
+
# change the individual log_levels in the solr admin interface.
|
146
|
+
# Default 'INFO'.
|
147
|
+
#
|
148
|
+
# ==== Returns
|
149
|
+
#
|
150
|
+
# String:: log_level
|
151
|
+
#
|
152
|
+
def log_level
|
153
|
+
@log_level ||= (user_configuration_from_key('solr', 'log_level') || 'INFO')
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Should the solr index receive a commit after each http-request.
|
158
|
+
# Default true
|
159
|
+
#
|
160
|
+
# ==== Returns
|
161
|
+
#
|
162
|
+
# Boolean: auto_commit_after_request?
|
163
|
+
#
|
164
|
+
def auto_commit_after_request?
|
165
|
+
@auto_commit_after_request ||=
|
166
|
+
user_configuration_from_key('auto_commit_after_request') != false
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# As for #auto_commit_after_request? but only for deletes
|
171
|
+
# Default false
|
172
|
+
#
|
173
|
+
# ==== Returns
|
174
|
+
#
|
175
|
+
# Boolean: auto_commit_after_delete_request?
|
176
|
+
#
|
177
|
+
def auto_commit_after_delete_request?
|
178
|
+
@auto_commit_after_delete_request ||=
|
179
|
+
(user_configuration_from_key('auto_commit_after_delete_request') || false)
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
#
|
184
|
+
# The log directory for solr logfiles
|
185
|
+
#
|
186
|
+
# ==== Returns
|
187
|
+
#
|
188
|
+
# String:: log_dir
|
189
|
+
#
|
190
|
+
def log_file
|
191
|
+
@log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location )
|
192
|
+
end
|
193
|
+
|
194
|
+
def data_path
|
195
|
+
@data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
|
196
|
+
end
|
197
|
+
|
198
|
+
def pid_dir
|
199
|
+
@pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
|
200
|
+
end
|
201
|
+
|
202
|
+
|
203
|
+
#
|
204
|
+
# The solr home directory. Sunspot::Rails expects this directory
|
205
|
+
# to contain a config, data and pids directory. See
|
206
|
+
# Sunspot::Rails::Server.bootstrap for more information.
|
207
|
+
#
|
208
|
+
# ==== Returns
|
209
|
+
#
|
210
|
+
# String:: solr_home
|
211
|
+
#
|
212
|
+
def solr_home
|
213
|
+
@solr_home ||=
|
214
|
+
if user_configuration_from_key('solr', 'solr_home')
|
215
|
+
user_configuration_from_key('solr', 'solr_home')
|
216
|
+
else
|
217
|
+
File.join(::Rails.root, 'solr')
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
#
|
222
|
+
# Solr start jar
|
223
|
+
#
|
224
|
+
def solr_jar
|
225
|
+
@solr_jar ||= user_configuration_from_key('solr', 'solr_jar')
|
226
|
+
end
|
227
|
+
|
228
|
+
#
|
229
|
+
# Minimum java heap size for Solr instance
|
230
|
+
#
|
231
|
+
def min_memory
|
232
|
+
@min_memory ||= user_configuration_from_key('solr', 'min_memory')
|
233
|
+
end
|
234
|
+
|
235
|
+
#
|
236
|
+
# Maximum java heap size for Solr instance
|
237
|
+
#
|
238
|
+
def max_memory
|
239
|
+
@max_memory ||= user_configuration_from_key('solr', 'max_memory')
|
240
|
+
end
|
241
|
+
|
242
|
+
private
|
243
|
+
|
244
|
+
#
|
245
|
+
# Logging in rails_root/log as solr_<environment>.log as a
|
246
|
+
# default.
|
247
|
+
#
|
248
|
+
# ===== Returns
|
249
|
+
#
|
250
|
+
# String:: default_log_file_location
|
251
|
+
#
|
252
|
+
def default_log_file_location
|
253
|
+
File.join(::Rails.root, 'log', "solr_" + ::Rails.env + ".log")
|
254
|
+
end
|
255
|
+
|
256
|
+
#
|
257
|
+
# return a specific key from the user configuration in config/sunspot.yml
|
258
|
+
#
|
259
|
+
# ==== Returns
|
260
|
+
#
|
261
|
+
# Mixed:: requested_key or nil
|
262
|
+
#
|
263
|
+
def user_configuration_from_key( *keys )
|
264
|
+
keys.inject(user_configuration) do |hash, key|
|
265
|
+
hash[key] if hash
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
#
|
270
|
+
# Memoized hash of configuration options for the current Rails environment
|
271
|
+
# as specified in config/sunspot.yml
|
272
|
+
#
|
273
|
+
# ==== Returns
|
274
|
+
#
|
275
|
+
# Hash:: configuration options for current environment
|
276
|
+
#
|
277
|
+
def user_configuration
|
278
|
+
@user_configuration ||=
|
279
|
+
begin
|
280
|
+
path = File.join(::Rails.root, 'config', 'sunspot.yml')
|
281
|
+
if File.exist?(path)
|
282
|
+
File.open(path) do |file|
|
283
|
+
processed = ERB.new(file.read).result
|
284
|
+
YAML.load(processed)[::Rails.env]
|
285
|
+
end
|
286
|
+
else
|
287
|
+
{}
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
protected
|
293
|
+
|
294
|
+
#
|
295
|
+
# When a specific hostname, port and path aren't provided in the
|
296
|
+
# sunspot.yml file, look for a key named 'url', then check the
|
297
|
+
# environment, then fall back to a sensible localhost default.
|
298
|
+
#
|
299
|
+
|
300
|
+
def solr_url
|
301
|
+
if ENV['SOLR_URL'] || ENV['WEBSOLR_URL']
|
302
|
+
URI.parse(ENV['SOLR_URL'] || ENV['WEBSOLR_URL'])
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def default_hostname
|
307
|
+
'localhost'
|
308
|
+
end
|
309
|
+
|
310
|
+
def default_port
|
311
|
+
{ 'test' => 8981,
|
312
|
+
'development' => 8982,
|
313
|
+
'production' => 8983
|
314
|
+
}[::Rails.env] || 8983
|
315
|
+
end
|
316
|
+
|
317
|
+
def default_path
|
318
|
+
'/solr'
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|