class SolrWrapper::Client

Solr REST API client to get status information

Attributes

url[R]

Public Class Methods

new(url) click to toggle source
# File lib/solr_wrapper/client.rb, line 9
def initialize(url)
  @url = url
end

Public Instance Methods

exists?(core_or_collection_name) click to toggle source

Check if a core or collection exists

# File lib/solr_wrapper/client.rb, line 14
def exists?(core_or_collection_name)
  collection?(core_or_collection_name) || core?(core_or_collection_name)
end

Private Instance Methods

collection?(name) click to toggle source
# File lib/solr_wrapper/client.rb, line 20
def collection?(name)
  response = HTTP.get("#{url}admin/collections?action=LIST&wt=json")
  data = JSON.parse(response.body)
  return if data['error'] && data['error']['msg'] == 'Solr instance is not running in SolrCloud mode.'

  data['collections'].include? name
end
core?(name) click to toggle source
# File lib/solr_wrapper/client.rb, line 28
def core?(name)
  response = HTTP.get("#{url}admin/cores?action=STATUS&wt=json&core=#{name}")
  !JSON.parse(response.body)['status'][name].empty?
end