Class: AboutPage::Solr

Inherits:
Configuration::Node show all
Defined in:
lib/about_page/solr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Configuration::Node

#add_header, #expects, #messages, render_with, #set_headers!

Constructor Details

#initialize(rsolr_instance, options = {}) ⇒ Solr

Returns a new instance of Solr.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/about_page/solr.rb', line 15

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

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/about_page/solr.rb', line 4

def options
  @options
end

#rsolrObject

Returns the value of attribute rsolr.



4
5
6
# File 'lib/about_page/solr.rb', line 4

def rsolr
  @rsolr
end

Instance Method Details

#indexObject



59
60
61
# File 'lib/about_page/solr.rb', line 59

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

#numDocsObject



67
# File 'lib/about_page/solr.rb', line 67

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

#pingObject



30
31
32
33
34
# File 'lib/about_page/solr.rb', line 30

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

#preflight(request) ⇒ Object



69
70
71
72
73
74
# File 'lib/about_page/solr.rb', line 69

def preflight request
  @schema = nil
  @registry = nil

  super
end

#registryObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/about_page/solr.rb', line 42

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

#schemaObject



36
37
38
39
40
# File 'lib/about_page/solr.rb', line 36

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

#to_hObject



63
64
65
# File 'lib/about_page/solr.rb', line 63

def to_h
  index#.merge(registry)
end