Sha256: 5734336422b170212091f2735d0f15ce15f5ad8d236f9dc43b8e739ec8730cc9

Contents?: true

Size: 986 Bytes

Versions: 1

Compression:

Stored size: 986 Bytes

Contents

module AboutPage
  class Solr  < AboutPage::Configuration::Node
    delegate :each_pair, :to_json, :to_xml, :to => :to_h

    attr_accessor :rsolr, :options

    def initialize rsolr_instance, options = {}
      self.rsolr = rsolr_instance
      self.options = options

      self.options[:minimum_numdocs] ||= 1
    end

    def schema
      @schema ||= rsolr.luke(:show => 'schema', :numTerms => 0)
    rescue
      {}
    end

    def index
      schema['index'] || {}
    end
    alias_method :to_h, :index

    def ok?
      true if index[:numDocs].to_i >= minimum_numdocs
    end

    def set_headers! response
      add_header(response, "solr numDocs: #{index[:numDocs]} < #{minimum_numdocs}") if index[:numDocs].to_i < minimum_numdocs
    end

    def preflight request
      @minimum_numdocs = request.params['solr.numDocs'].to_i if request.params['solr.numDocs'].to_i
    end

    def minimum_numdocs
      @minimum_numdocs || self.options[:minimum_numdocs]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
about_page-0.0.1 lib/about_page/solr.rb