Sha256: 5ce3149227c6278d136493df7620f7d43b700431eda0d810fbbe315cdac949ac

Contents?: true

Size: 842 Bytes

Versions: 11

Compression:

Stored size: 842 Bytes

Contents

require 'http'
require 'json'

module SolrWrapper
  # Solr REST API client to get status information
  class Client
    attr_reader :url

    def initialize(url)
      @url = url
    end

    # Check if a core or collection exists
    def exists?(core_or_collection_name)
      collection?(core_or_collection_name) || core?(core_or_collection_name)
    end

    private

    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

    def core?(name)
      response = HTTP.get("#{url}admin/cores?action=STATUS&wt=json&core=#{name}")
      !JSON.parse(response.body)['status'][name].empty?
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/solr_wrapper-4.0.2/lib/solr_wrapper/client.rb
solr_wrapper-4.0.2 lib/solr_wrapper/client.rb
solr_wrapper-4.0.1 lib/solr_wrapper/client.rb
solr_wrapper-4.0.0 lib/solr_wrapper/client.rb
solr_wrapper-3.1.3 lib/solr_wrapper/client.rb
solr_wrapper-3.1.2 lib/solr_wrapper/client.rb
solr_wrapper-3.1.1 lib/solr_wrapper/client.rb
solr_wrapper-3.1.0 lib/solr_wrapper/client.rb
solr_wrapper-3.0.2 lib/solr_wrapper/client.rb
solr_wrapper-3.0.1 lib/solr_wrapper/client.rb
solr_wrapper-3.0.0 lib/solr_wrapper/client.rb