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, #set_headers!

Constructor Details

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

Returns a new instance of Solr.



15
16
17
18
19
20
21
22
# File 'lib/about_page/solr.rb', line 15

def initialize rsolr_instance, options = {}
  self.rsolr = rsolr_instance
  self.options = options
  self.options[:expects] ||= {}
  self.options[:expects][:numDocs] ||= 1

  @request_expectations = {}
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#rsolrObject

Returns the value of attribute rsolr.



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

def rsolr
  @rsolr
end

Instance Method Details

#indexObject



47
48
49
# File 'lib/about_page/solr.rb', line 47

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

#numDocsObject



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

def numDocs; index[:numDocs]; end

#preflight(request) ⇒ Object



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

def preflight request
  @schema = nil
  @registry = nil

  super
end

#registryObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/about_page/solr.rb', line 30

def registry
  @registry ||= begin
                  h = {}
                  resp = rsolr.get 'admin/registry.jsp', :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



24
25
26
27
28
# File 'lib/about_page/solr.rb', line 24

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

#to_hObject



51
52
53
# File 'lib/about_page/solr.rb', line 51

def to_h
  index.merge(registry)
end