Class: Sunspot::Rails::Configuration

Inherits:
Object
  • Object
show all
Defined in:
sunspot_rails/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
      min_memory: 512M
      max_memory: 1G
      solr_jar: /some/path/solr15/start.jar
      bind_address: 0.0.0.0
    disabled: false
  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
    master_solr:
      hostname: localhost
      port: 8982
      path: /solr
    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.

If the master_solr configuration is present, Sunspot will use the Solr instance specified here for all write operations, and the Solr configured under solr for all read operations.

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) auto_commit_after_delete_request?

As for #auto_commit_after_request? but only for deletes Default false

Returns

Boolean: auto_commit_after_delete_request?

Returns:

  • (Boolean)


179
180
181
182
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 179

def auto_commit_after_delete_request?
  @auto_commit_after_delete_request ||= 
    (user_configuration_from_key('auto_commit_after_delete_request') || false)
end

- (Boolean) auto_commit_after_request?

Should the solr index receive a commit after each http-request. Default true

Returns

Boolean: auto_commit_after_request?

Returns:

  • (Boolean)


166
167
168
169
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 166

def auto_commit_after_request?
  @auto_commit_after_request ||= 
    user_configuration_from_key('auto_commit_after_request') != false
end

- (Object) bind_address

Interface on which to run Solr



247
248
249
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 247

def bind_address
  @bind_address ||= user_configuration_from_key('solr', 'bind_address')
end

- (Object) data_path



196
197
198
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 196

def data_path
  @data_path ||= user_configuration_from_key('solr', 'data_path') || File.join(::Rails.root, 'solr', 'data', ::Rails.env)
end

- (Boolean) disabled?

Whether or not to disable Solr. Defaults to false.

Returns:

  • (Boolean)


255
256
257
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 255

def disabled?
  @disabled ||= (user_configuration_from_key('disabled') || false)
end

- (Boolean) has_master?

True if there is a master Solr instance configured, otherwise false.

Returns

Boolean

bool

Returns:

  • (Boolean)


141
142
143
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 141

def has_master?
  @has_master = !!user_configuration_from_key('master_solr')
end

- (Object) hostname

The host name at which to connect to Solr. Default ‘localhost’.

Returns

String

host name



54
55
56
57
58
59
60
61
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 54

def hostname
  unless defined?(@hostname)
    @hostname   = solr_url.host if solr_url
    @hostname ||= user_configuration_from_key('solr', 'hostname')
    @hostname ||= default_hostname
  end
  @hostname
end

- (Object) log_file

The log directory for solr logfiles

Returns

String

log_dir



192
193
194
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 192

def log_file
  @log_file ||= (user_configuration_from_key('solr', 'log_file') || default_log_file_location )
end

- (Object) log_level

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



154
155
156
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 154

def log_level
  @log_level ||= (user_configuration_from_key('solr', 'log_level') || 'INFO')
end

- (Object) master_hostname

The host name at which to connect to the master Solr instance. Defaults to the ‘hostname’ configuration option.

Returns

String

host name



106
107
108
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 106

def master_hostname
  @master_hostname ||= (user_configuration_from_key('master_solr', 'hostname') || hostname)
end

- (Object) master_path

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



130
131
132
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 130

def master_path
  @master_path ||= (user_configuration_from_key('master_solr', 'path') || path)
end

- (Object) master_port

The port at which to connect to the master Solr instance. Defaults to the ‘port’ configuration option.

Returns

Integer

port



118
119
120
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 118

def master_port
  @master_port ||= (user_configuration_from_key('master_solr', 'port') || port).to_i
end

- (Object) max_memory

Maximum java heap size for Solr instance



240
241
242
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 240

def max_memory
  @max_memory ||= user_configuration_from_key('solr', 'max_memory')
end

- (Object) min_memory

Minimum java heap size for Solr instance



233
234
235
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 233

def min_memory
  @min_memory ||= user_configuration_from_key('solr', 'min_memory')
end

- (Object) path

The url path to the Solr servlet (useful if you are running multicore). Default ’/solr’.

Returns

String

path



89
90
91
92
93
94
95
96
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 89

def path
  unless defined?(@path)
    @path   = solr_url.path if solr_url
    @path ||= user_configuration_from_key('solr', 'path')
    @path ||= default_path
  end
  @path
end

- (Object) pid_dir



200
201
202
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 200

def pid_dir
  @pid_dir ||= user_configuration_from_key('solr', 'pid_dir') || File.join(::Rails.root, 'solr', 'pids', ::Rails.env)
end

- (Object) port

The port at which to connect to Solr. Defaults to 8981 in test, 8982 in development and 8983 in production.

Returns

Integer

port



71
72
73
74
75
76
77
78
79
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 71

def port
  unless defined?(@port)
    @port   = solr_url.port if solr_url
    @port ||= user_configuration_from_key('solr', 'port')
    @port ||= default_port
    @port   = @port.to_i
  end
  @port
end

- (Object) solr_home

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



214
215
216
217
218
219
220
221
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 214

def solr_home
  @solr_home ||=
    if user_configuration_from_key('solr', 'solr_home')
      user_configuration_from_key('solr', 'solr_home')
    else
      File.join(::Rails.root, 'solr')
    end
end

- (Object) solr_jar

Solr start jar



226
227
228
# File 'sunspot_rails/lib/sunspot/rails/configuration.rb', line 226

def solr_jar
  @solr_jar ||= user_configuration_from_key('solr', 'solr_jar')
end