Class: Sunspot::Rails::Configuration
- Inherits:
-
Object
- Object
- Sunspot::Rails::Configuration
- Defined in:
- lib/sunspot/rails/configuration.rb
Overview
Sunspot::Rails is configured via the config/sunspot.yml file, which contains properties keyed by environment name. A sample sunspot.yml file would look like:
development:
solr:
hostname: localhost
port: 8982
test:
solr:
hostname: localhost
port: 8983
log_level: OFF
production:
solr:
hostname: localhost
port: 8983
path: /solr/myindex
log_level: WARNING
solr_home: /some/path
auto_commit_after_request: true
Sunspot::Rails uses the configuration to set up the Solr connection, as well as for starting Solr with the appropriate port using the rake sunspot:solr:start
task.
Instance Attribute Summary collapse
-
#user_configuration ⇒ Object
writeonly
Sets the attribute user_configuration.
Instance Method Summary collapse
-
#auto_commit_after_request? ⇒ Boolean
Should the solr index receive a commit after each http-request.
- #data_path ⇒ Object
-
#hostname ⇒ Object
The host name at which to connect to Solr.
-
#log_file ⇒ Object
The log directory for solr logfiles.
-
#log_level ⇒ Object
The default log_level that should be passed to solr.
-
#master? ⇒ Boolean
True if there is a master Solr instance configured, otherwise false.
-
#master_hostname ⇒ Object
The host name at which to connect to the master Solr instance.
-
#master_path ⇒ Object
The path to the master Solr servlet (useful if you are running multicore).
-
#master_port ⇒ Object
The port at which to connect to the master Solr instance.
-
#path ⇒ Object
The url path to the Solr servlet (useful if you are running multicore).
- #pid_path ⇒ Object
-
#port ⇒ Object
The port at which to connect to Solr.
-
#solr_home ⇒ Object
The solr home directory.
Instance Attribute Details
#user_configuration=(value) ⇒ Object
Sets the attribute user_configuration
31 32 33 |
# File 'lib/sunspot/rails/configuration.rb', line 31 def user_configuration=(value) @user_configuration = value end |
Instance Method Details
#auto_commit_after_request? ⇒ Boolean
Should the solr index receive a commit after each http-request. Default true
Returns
- Boolean
-
bool
130 131 132 133 |
# File 'lib/sunspot/rails/configuration.rb', line 130 def auto_commit_after_request? @auto_commit_after_request ||= user_configuration_from_key('auto_commit_after_request') != false end |
#data_path ⇒ Object
146 147 148 |
# File 'lib/sunspot/rails/configuration.rb', line 146 def data_path @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env) end |
#hostname ⇒ Object
The host name at which to connect to Solr. Default ‘localhost’.
Returns
- String
-
host name
39 40 41 |
# File 'lib/sunspot/rails/configuration.rb', line 39 def hostname @hostname ||= (user_configuration_from_key('solr', 'hostname') || 'localhost') end |
#log_file ⇒ Object
The log directory for solr logfiles
Returns
- String
-
log_dir
142 143 144 |
# File 'lib/sunspot/rails/configuration.rb', line 142 def log_file @log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location ) end |
#log_level ⇒ Object
The default log_level that should be passed to solr. You can change the individual log_levels in the solr admin interface. Default ‘INFO’.
Returns
- String
-
log_level
122 123 124 |
# File 'lib/sunspot/rails/configuration.rb', line 122 def log_level @log_level ||= (user_configuration_from_key('solr', 'log_level') || 'INFO') end |
#master? ⇒ Boolean
True if there is a master Solr instance configured, otherwise false.
Returns
- Boolean
-
bool
109 110 111 |
# File 'lib/sunspot/rails/configuration.rb', line 109 def master? master_hostname != hostname || master_port != port || master_path != path end |
#master_hostname ⇒ Object
The host name at which to connect to the master Solr instance. Defaults to the ‘hostname’ configuration option.
Returns
- String
-
host name
74 75 76 |
# File 'lib/sunspot/rails/configuration.rb', line 74 def master_hostname @master_hostname ||= (user_configuration_from_key('solr', 'master_hostname') || hostname) end |
#master_path ⇒ Object
The path to the master Solr servlet (useful if you are running multicore). Defaults to the value of the ‘path’ configuration option.
Returns
- String
-
path
98 99 100 |
# File 'lib/sunspot/rails/configuration.rb', line 98 def master_path @master_path ||= (user_configuration_from_key('solr', 'master_path') || path) end |
#master_port ⇒ Object
The port at which to connect to the master Solr instance. Defaults to the ‘port’ configuration option.
Returns
- Integer
-
port
86 87 88 |
# File 'lib/sunspot/rails/configuration.rb', line 86 def master_port @master_port ||= (user_configuration_from_key('solr', 'master_port') || port).to_i end |
#path ⇒ Object
The url path to the Solr servlet (useful if you are running multicore). Default ‘/solr’.
Returns
- String
-
path
62 63 64 |
# File 'lib/sunspot/rails/configuration.rb', line 62 def path @path ||= (user_configuration_from_key('solr', 'path') || '/solr') end |
#pid_path ⇒ Object
150 151 152 |
# File 'lib/sunspot/rails/configuration.rb', line 150 def pid_path @pids_path ||= user_configuration_from_key('solr', 'pid_path') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env) end |
#port ⇒ Object
The port at which to connect to Solr. Default 8983.
Returns
- Integer
-
port
50 51 52 |
# File 'lib/sunspot/rails/configuration.rb', line 50 def port @port ||= (user_configuration_from_key('solr', 'port') || 8983).to_i end |
#solr_home ⇒ Object
The solr home directory. Sunspot::Rails expects this directory to contain a config, data and pids directory. See Sunspot::Rails::Server.bootstrap for more information.
Returns
- String
-
solr_home
176 177 178 179 180 181 182 183 |
# File 'lib/sunspot/rails/configuration.rb', line 176 def solr_home @solr_home ||= if user_configuration_from_key('solr', 'solr_home') user_configuration_from_key('solr', 'solr_home') elsif %w(solrconfig schema).all? { |file| File.exist?(File.join(::Rails.root, 'solr', 'conf', "#{file}.xml")) } File.join(::Rails.root, 'solr') end end |