Class: Ferret::Search::ScoreDoc

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ferret/search/score_doc.rb

Overview

Expert: Returned by low-level search implementations. See TopDocs

Direct Known Subclasses

FieldDoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, score) ⇒ ScoreDoc

Expert: Constructs a ScoreDoc.



13
14
15
16
# File 'lib/ferret/search/score_doc.rb', line 13

def initialize(doc, score) 
  @doc = doc
  @score = score
end

Instance Attribute Details

#docObject

Expert: A hit document’s number.



10
11
12
# File 'lib/ferret/search/score_doc.rb', line 10

def doc
  @doc
end

#scoreObject

Expert: The score of this document for the query.



7
8
9
# File 'lib/ferret/search/score_doc.rb', line 7

def score
  @score
end

Instance Method Details

#<=>(other) ⇒ Object

score_docA < score_docB if score_docA.score < score_docB.score or score_docA.doc > score_docB.doc



25
26
27
28
29
30
31
32
# File 'lib/ferret/search/score_doc.rb', line 25

def <=>(other)
  result = @score.<=>(other.score)
  if (result == 0)
    return other.doc.<=>(@doc)
  else
    return result
  end
end

#hashObject

returns a hash value for storage in a Hash



19
20
21
# File 'lib/ferret/search/score_doc.rb', line 19

def hash()
  return 100 * doc * score
end

#to_sObject



34
35
36
# File 'lib/ferret/search/score_doc.rb', line 34

def to_s
  "#{@doc} -> %0.2f" % @score
end