class ActiveFedora::SolrService

Constants

MAX_ROWS

Attributes

conn[W]
options[R]

Public Class Methods

add(doc, params = {}) click to toggle source

@param [Hash] doc the document to index, or an array of docs @param [Hash] params

:commit => commits immediately
:softCommit => commit to memory, but don't flush to disk
# File lib/active_fedora/solr_service.rb, line 84
def add(doc, params = {})
  SolrService.instance.conn.add(doc, params: params)
end
commit() click to toggle source
# File lib/active_fedora/solr_service.rb, line 88
def commit
  SolrService.instance.conn.commit
end
count(query, args = {}) click to toggle source

Get the count of records that match the query @param [String] query a solr query @param [Hash] args arguments to pass through to ‘args’ param of SolrService.query (note that :rows will be overwritten to 0) @return [Integer] number of records matching

# File lib/active_fedora/solr_service.rb, line 75
def count(query, args = {})
  args = args.merge(rows: 0)
  SolrService.get(query, args)['response']['numFound'].to_i
end
delete(id) click to toggle source
# File lib/active_fedora/solr_service.rb, line 67
def delete(id)
  SolrService.instance.conn.delete_by_id(id, params: { 'softCommit' => true })
end
get(query, args = {}) click to toggle source
# File lib/active_fedora/solr_service.rb, line 40
def get(query, args = {})
  args = args.merge(q: query, qt: 'standard')
  SolrService.instance.conn.get(select_path, params: args)
end
instance() click to toggle source
# File lib/active_fedora/solr_service.rb, line 32
def instance
  # Register Solr

  register(ActiveFedora.solr_config) unless ActiveFedora::RuntimeRegistry.solr_service

  ActiveFedora::RuntimeRegistry.solr_service
end
new(options = {}) click to toggle source
# File lib/active_fedora/solr_service.rb, line 10
def initialize(options = {})
  @options = { timeout: 120, open_timeout: 120, url: 'http://localhost:8080/solr' }.merge(options)
end
post(query, args = {}) click to toggle source
# File lib/active_fedora/solr_service.rb, line 45
def post(query, args = {})
  args = args.merge(q: query, qt: 'standard')
  SolrService.instance.conn.post(select_path, data: args)
end
query(query, args = {}) click to toggle source
# File lib/active_fedora/solr_service.rb, line 50
def query(query, args = {})
  Base.logger.warn "Calling ActiveFedora::SolrService.get without passing an explicit value for ':rows' is not recommended. You will end up with Solr's default (usually set to 10)\nCalled by #{caller[0]}" unless args.key?(:rows)
  method = args.delete(:method) || :get

  result = case method
           when :get
             get(query, args)
           when :post
             post(query, args)
           else
             raise "Unsupported HTTP method for querying SolrService (#{method.inspect})"
           end
  result['response']['docs'].map do |doc|
    ActiveFedora::SolrHit.new(doc)
  end
end
register(options = {}) click to toggle source

@param [Hash] options

# File lib/active_fedora/solr_service.rb, line 20
def register(options = {})
  ActiveFedora::RuntimeRegistry.solr_service = new(options)
end
reset!() click to toggle source
# File lib/active_fedora/solr_service.rb, line 24
def reset!
  ActiveFedora::RuntimeRegistry.solr_service = nil
end
select_path() click to toggle source
# File lib/active_fedora/solr_service.rb, line 28
def select_path
  ActiveFedora.solr_config.fetch(:select_path, 'select')
end

Public Instance Methods

conn() click to toggle source
# File lib/active_fedora/solr_service.rb, line 14
def conn
  @conn ||= RSolr.connect @options
end