Class: Sunspot::Padrino::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sunspot/padrino/configuration.rb

Overview

Sunspot::Padrino 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
    open_timeout: 0.5
    read_timeout: 2
production:
  solr:
    scheme: http
    user: username
    pass: password
    hostname: localhost
    port: 8983
    path: /solr/myindex
    log_level: WARNING
    solr_home: /some/path
    open_timeout: 0.5
    read_timeout: 2
  master_solr:
    hostname: localhost
    port: 8982
    path: /solr
  auto_commit_after_request: true

Sunspot::Padrino 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.

Constant Summary collapse

LOG_LEVELS =

ActiveSupport log levels are integers; this array maps them to the appropriate java.util.logging.Level constant

%w(FINE INFO WARNING SEVERE SEVERE INFO)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#user_configuration=(value) ⇒ Object

Sets the attribute user_configuration

Parameters:

  • value

    the value to set the attribute user_configuration to.



55
56
57
# File 'lib/sunspot/padrino/configuration.rb', line 55

def user_configuration=(value)
  @user_configuration = value
end

Instance Method Details

#auto_commit_after_delete_request?Boolean

As for #auto_commit_after_request? but only for deletes Default false

Returns

Boolean: auto_commit_after_delete_request?

Returns:

  • (Boolean)


228
229
230
231
# File 'lib/sunspot/padrino/configuration.rb', line 228

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

#auto_commit_after_request?Boolean

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

Returns

Boolean: auto_commit_after_request?

Returns:

  • (Boolean)


215
216
217
218
# File 'lib/sunspot/padrino/configuration.rb', line 215

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

#bind_addressObject

Interface on which to run Solr



296
297
298
# File 'lib/sunspot/padrino/configuration.rb', line 296

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

#data_pathObject



245
246
247
# File 'lib/sunspot/padrino/configuration.rb', line 245

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

#disabled?Boolean

Whether or not to disable Solr. Defaults to false.

Returns:

  • (Boolean)


312
313
314
# File 'lib/sunspot/padrino/configuration.rb', line 312

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

#has_master?Boolean

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

Returns

Boolean

bool

Returns:

  • (Boolean)


186
187
188
# File 'lib/sunspot/padrino/configuration.rb', line 186

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

#hostnameObject

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

Returns

String

host name



63
64
65
66
67
68
69
70
# File 'lib/sunspot/padrino/configuration.rb', line 63

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

#log_fileObject

The log directory for solr logfiles

Returns

String

log_dir



241
242
243
# File 'lib/sunspot/padrino/configuration.rb', line 241

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

#log_levelObject

The default log_level that should be passed to solr. You can change the individual log_levels in the solr admin interface. If no level is specified in the sunspot configuration file, use a level similar to Padrino own logging level.

Returns

String

log_level



200
201
202
203
204
205
# File 'lib/sunspot/padrino/configuration.rb', line 200

def log_level
  @log_level ||= (
    user_configuration_from_key('solr', 'log_level') ||
    LOG_LEVELS[::Padrino.logger.level]
  )
end

#master_hostnameObject

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

Returns

String

host name



151
152
153
# File 'lib/sunspot/padrino/configuration.rb', line 151

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

#master_pathObject

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



175
176
177
# File 'lib/sunspot/padrino/configuration.rb', line 175

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

#master_portObject

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

Returns

Integer

port



163
164
165
# File 'lib/sunspot/padrino/configuration.rb', line 163

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

#max_memoryObject

Maximum java heap size for Solr instance



289
290
291
# File 'lib/sunspot/padrino/configuration.rb', line 289

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

#min_memoryObject

Minimum java heap size for Solr instance



282
283
284
# File 'lib/sunspot/padrino/configuration.rb', line 282

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

#open_timeoutObject



304
305
306
# File 'lib/sunspot/padrino/configuration.rb', line 304

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

#pathObject

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

Returns

String

path



134
135
136
137
138
139
140
141
# File 'lib/sunspot/padrino/configuration.rb', line 134

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

#pid_dirObject



249
250
251
# File 'lib/sunspot/padrino/configuration.rb', line 249

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

#portObject

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

Returns

Integer

port



80
81
82
83
84
85
86
87
88
# File 'lib/sunspot/padrino/configuration.rb', line 80

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

#read_timeoutObject



300
301
302
# File 'lib/sunspot/padrino/configuration.rb', line 300

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

#schemeObject

The scheme to use, http or https. Defaults to http

Returns

String

scheme



98
99
100
101
102
103
104
105
# File 'lib/sunspot/padrino/configuration.rb', line 98

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

#solr_homeObject

The solr home directory. Sunspot::Padrino expects this directory to contain a config, data and pids directory. See Sunspot::Padrino::Server.bootstrap for more information.

Returns

String

solr_home



263
264
265
266
267
268
269
270
# File 'lib/sunspot/padrino/configuration.rb', line 263

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

#solr_jarObject

Solr start jar



275
276
277
# File 'lib/sunspot/padrino/configuration.rb', line 275

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

#userinfoObject

The userinfo used for authentication, a colon-delimited string like “user:pass” Defaults to nil, which means no authentication

Returns

String

userinfo



115
116
117
118
119
120
121
122
123
124
# File 'lib/sunspot/padrino/configuration.rb', line 115

def userinfo
  unless defined?(@userinfo)
    @userinfo   = solr_url.userinfo if solr_url
    user = user_configuration_from_key('solr', 'user')
    pass = user_configuration_from_key('solr', 'pass')
    @userinfo ||= [ user, pass ].compact.join(":") if user && pass
    @userinfo ||= default_userinfo
  end
  @userinfo
end