Sha256: 6d763c932f36a53d4306036192291cfeb0d107d603a158a9d2f7696e59465c4b

Contents?: true

Size: 892 Bytes

Versions: 22

Compression:

Stored size: 892 Bytes

Contents

require 'faraday'
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 = conn.get('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 = conn.get('admin/cores?action=STATUS&wt=json&core=' + name)
      !JSON.parse(response.body)['status'][name].empty?
    end

    def conn
      @conn ||= Faraday.new(url: url)
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
solr_wrapper-2.2.0 lib/solr_wrapper/client.rb
solr_wrapper-2.1.0 lib/solr_wrapper/client.rb
solr_wrapper-2.0.0 lib/solr_wrapper/client.rb
solr_wrapper-1.2.0 lib/solr_wrapper/client.rb
solr_wrapper-1.1.0 lib/solr_wrapper/client.rb
solr_wrapper-1.0.0 lib/solr_wrapper/client.rb
solr_wrapper-0.23.0 lib/solr_wrapper/client.rb
solr_wrapper-0.22.0 lib/solr_wrapper/client.rb
solr_wrapper-0.21.0 lib/solr_wrapper/client.rb
solr_wrapper-0.20.0 lib/solr_wrapper/client.rb
solr_wrapper-0.19.0 lib/solr_wrapper/client.rb
solr_wrapper-0.18.1 lib/solr_wrapper/client.rb
solr_wrapper-0.18.0 lib/solr_wrapper/client.rb
solr_wrapper-0.17.0 lib/solr_wrapper/client.rb
solr_wrapper-0.16.0 lib/solr_wrapper/client.rb
solr_wrapper-0.15.0 lib/solr_wrapper/client.rb
solr_wrapper-0.14.2 lib/solr_wrapper/client.rb
solr_wrapper-0.14.1 lib/solr_wrapper/client.rb
solr_wrapper-0.14.0 lib/solr_wrapper/client.rb
solr_wrapper-0.13.2 lib/solr_wrapper/client.rb