Skip to content
Chris Beer edited this page Feb 1, 2014 · 8 revisions

Connecting to Solr

The Solr connection parameters are configured globally in config/solr.yml. Out of the box, it looks something like this:

# config/solr.yml
development:
  url: <%= ENV['SOLR_URL'] || "http://127.0.0.1:8983/solr" %>
test: &test
  url: <%= "http://127.0.0.1:#{ENV['TEST_JETTY_PORT'] || 8888}/solr" %>

Blacklight parses the YAML file using ERB, which means you can use environment variables (as above), class methods, etc.

The configuration is used to configure RSolr::Client. Available options include:

  • url
  • proxy
  • open_timeout
  • read_timeout
  • retry_503
  • retry_after_limit

(Advanced) Solr Unique Key

If your solr configuration uses a unique field other than id, you must configure your SolrDocument class (in app/models/solr_document.rb) to set the unique key:

# app/models/solr_document.rb

class SolrDocument
  include Blacklight::Solr::Document

  self.unique_key = 'my_unique_key_field'
 
  ...
end

Advanced: Run-time configuration

The solr.yml file works for static, global Solr connections. Some use cases require dynamic configuration (based on the request or otherwise). Blacklight provides instance-level accessor methods for the Solr connection. By overriding these accessors, applications can provide either custom RSolr clients (e.g. rsolr-async) or per-user or per-controller solr connections:

class CatalogController < ApplicationController
  include Blacklight::Catalog
  include MyApplicationRuntimeConfiguration
end

module MyApplicationRuntimeConfiguration
  def blacklight_solr
    @blacklight_solr ||= RSolr::Custom::Client.new :user => current_user.id
  end
end
Clone this wiki locally