Sha256: 235ef09693ce4cc6c45c25a05510297fd3c107ef7a5a26d61e5009de90265a33

Contents?: true

Size: 1.81 KB

Versions: 10

Compression:

Stored size: 1.81 KB

Contents

module AboutPage
  class Solr  < AboutPage::Configuration::Node
    
    attr_accessor :rsolr, :options

    validates_each :ping do |record, attr, value|
      unless value == 'OK'
        record.errors.add attr, ": unable to ping Solr at #{record.rsolr.uri.to_s}"
      end
    end
    validates :numDocs, :numericality => { :greater_than_or_equal_to => Proc.new { |c| c.expects(:numDocs) } }

    render_with 'generic_hash'

    def initialize rsolr_instance, options = {}
      self.rsolr = rsolr_instance
      self.options = options
      self.options[:luke]     ||= 'admin/luke'
      if self.options[:registry] == :registry
        self.options[:registry] = 'admin/registry.jsp'
      else
        self.options[:registry] ||= 'admin/mbeans'
      end
      self.options[:expects]  ||= {}
      self.options[:expects][:numDocs] ||= 1

      @request_expectations = {}
    end

    def ping
      rsolr.get('admin/ping')['status']
    rescue
      nil
    end

    def schema
      @schema ||= rsolr.get self.options[:luke], :params => { :show => 'schema', :numTerms => 0 }
    rescue
      {}
    end

    def registry
      @registry ||= begin
                      h = {}
                      resp = rsolr.get self.options[:registry], :params => { :wt => 'xml' }
                      doc = Nokogiri::XML resp

                      doc.xpath('/solr/*').each do |node|
                        next if node.name == "solr-info"
                        h[node.name] = node.text
                      end

                      h
                    end
    rescue
      {}
    end

    def index
      (schema || {})['index'] || {}
    end

    def to_h
      index#.merge(registry)
    end

    def numDocs; index[:numDocs] || index['numDocs']; end

    def preflight request
      @schema = nil
      @registry = nil

      super
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
about_page-0.3.1 lib/about_page/solr.rb
about_page-0.3.0 lib/about_page/solr.rb
about_page-0.2.7 lib/about_page/solr.rb
about_page-0.2.6 lib/about_page/solr.rb
about_page-0.2.5 lib/about_page/solr.rb
about_page-0.2.4 lib/about_page/solr.rb
about_page-0.2.3 lib/about_page/solr.rb
about_page-0.2.2 lib/about_page/solr.rb
about_page-0.2.1 lib/about_page/solr.rb
about_page-0.2.0 lib/about_page/solr.rb