Class: SimpleSolrClient::Response::Document

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/simple_solr_client/response/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(solrdochash) ⇒ Document

Create a single document from a Hash representation of the solr return value as returned by a solr query

Parameters:

  • solrdochash (Hash)

    The ruby-hash representation of a Solr document



25
26
27
# File 'lib/simple_solr_client/response/document.rb', line 25

def initialize(solrdochash)
  @solr_doc_hash = solrdochash
end

Instance Attribute Details

#rankObject

!@attribute solr_doc_hash

@return [Hash] the original, un-munged solr data for this document passed into the initializer


19
20
21
# File 'lib/simple_solr_client/response/document.rb', line 19

def rank
  @rank
end

#solr_doc_hashObject

!@attribute solr_doc_hash

@return [Hash] the original, un-munged solr data for this document passed into the initializer


19
20
21
# File 'lib/simple_solr_client/response/document.rb', line 19

def solr_doc_hash
  @solr_doc_hash
end

Instance Method Details

#<=>(other) ⇒ Object



7
8
9
10
# File 'lib/simple_solr_client/response/document.rb', line 7

def <=>(other)
  other = other.score if other.respond_to? :score,
                                           self.score <=> other
end

#[](key) ⇒ String+

Returns the value(s) of the requested field.

Parameters:

  • key (String)

    The name of the stored field

Returns:

  • (String, Array<String>)

    the value(s) of the requested field



15
# File 'lib/simple_solr_client/response/document.rb', line 15

def_delegators :@solr_doc_hash, :[], :keys, :values, :to_s

#idObject

The value of the ‘id’ field of this document



31
32
33
# File 'lib/simple_solr_client/response/document.rb', line 31

def id
  @solr_doc_hash['id']
end

#scoreObject

The score of this document on thsi query



36
37
38
# File 'lib/simple_solr_client/response/document.rb', line 36

def score
  @solr_doc_hash['score']
end

#to_hObject



41
42
43
# File 'lib/simple_solr_client/response/document.rb', line 41

def to_h
  @solr_doc_hash.merge({'_rank' => @rank})
end