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
production:
solr:
hostname: localhost
port: 8983
path: /solr/myindex
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
The path to the Solr indexes.
-
#hostname ⇒ Object
The host name at which to connect to Solr.
-
#path ⇒ Object
The url path to the Solr servlet (useful if you are running multicore).
-
#pid_path ⇒ Object
The path to the Solr pids Default RAILS_ROOT + ‘/solr/pids/’ + ENVIRONMENT.
-
#port ⇒ Object
The port at which to connect to Solr.
-
#solr_home ⇒ Object
The path to the Solr home directory Default nil (runs the solr with sunspot default settings).
Instance Attribute Details
#user_configuration=(value) ⇒ Object
Sets the attribute user_configuration
28 29 30 |
# File 'lib/sunspot/rails/configuration.rb', line 28 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
72 73 74 75 |
# File 'lib/sunspot/rails/configuration.rb', line 72 def auto_commit_after_request? @auto_commit_after_request ||= user_configuration_from_key('auto_commit_after_request') != false end |
#data_path ⇒ Object
The path to the Solr indexes. (Used by the rake tasks). Default RAILS_ROOT + ‘/solr/data/’ + ENVIRONMENT
Returns
- String
-
path
85 86 87 88 89 90 |
# File 'lib/sunspot/rails/configuration.rb', line 85 def data_path @data_path ||= if user_configuration.has_key?('solr') "#{user_configuration['solr']['data_path'] || File.join(::Rails.root, 'solr', 'data', ::Rails.env)}" end end |
#hostname ⇒ Object
The host name at which to connect to Solr. Default ‘localhost’.
Returns
- String
-
host name
36 37 38 |
# File 'lib/sunspot/rails/configuration.rb', line 36 def hostname @hostname ||= (user_configuration_from_key('solr', 'hostname') || 'localhost') end |
#path ⇒ Object
The url path to the Solr servlet (useful if you are running multicore). Default ‘/solr’.
Returns
- String
-
path
59 60 61 |
# File 'lib/sunspot/rails/configuration.rb', line 59 def path @path ||= (user_configuration_from_key('solr', 'path') || '/solr') end |
#pid_path ⇒ Object
The path to the Solr pids Default RAILS_ROOT + ‘/solr/pids/’ + ENVIRONMENT
Returns
- String
-
path
100 101 102 103 104 105 |
# File 'lib/sunspot/rails/configuration.rb', line 100 def pid_path @pids_path ||= if user_configuration.has_key?('solr') "#{user_configuration['solr']['pid_path'] || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)}" end end |
#port ⇒ Object
The port at which to connect to Solr. Default 8983.
Returns
- Integer
-
port
47 48 49 |
# File 'lib/sunspot/rails/configuration.rb', line 47 def port @port ||= (user_configuration_from_key('solr', 'port') || 8983).to_i end |
#solr_home ⇒ Object
The path to the Solr home directory Default nil (runs the solr with sunspot default settings).
If you have a custom solr conf directory, change this to the directory above your solr conf files
e.g. conf files in RAILS_ROOT/solr/conf
solr_home: RAILS_ROOT/solr
Returns
- String
-
path
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sunspot/rails/configuration.rb', line 121 def solr_home @solr_home ||= if user_configuration.has_key?('solr') if user_configuration['solr']['solr_home'].present? user_configuration['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 end |