Class: Ferret::Search::TopDocs
- Inherits:
-
Object
- Object
- Ferret::Search::TopDocs
- Defined in:
- lib/ferret/search/top_docs.rb
Overview
Expert: Returned by low-level search implementations. See Searcher#search
Direct Known Subclasses
Instance Attribute Summary collapse
-
#fields ⇒ Object
Expert: The total number of hits for the query.
-
#score_docs ⇒ Object
Expert: The total number of hits for the query.
-
#total_hits ⇒ Object
(also: #size)
Expert: The total number of hits for the query.
Instance Method Summary collapse
-
#each ⇒ Object
iterate through each of the score docs, yielding the document number and the score.
-
#initialize(total_hits, score_docs, fields = SortField::FIELD_SCORE) ⇒ TopDocs
constructor
Expert: Constructs a TopDocs.
- #to_s ⇒ Object
Constructor Details
#initialize(total_hits, score_docs, fields = SortField::FIELD_SCORE) ⇒ TopDocs
Expert: Constructs a TopDocs.
22 23 24 25 26 |
# File 'lib/ferret/search/top_docs.rb', line 22 def initialize(total_hits, score_docs, fields = SortField::FIELD_SCORE) @total_hits = total_hits @score_docs = score_docs @fields = fields end |
Instance Attribute Details
#fields ⇒ Object
Expert: The total number of hits for the query. See Hits#length()
7 8 9 |
# File 'lib/ferret/search/top_docs.rb', line 7 def fields @fields end |
#score_docs ⇒ Object
Expert: The total number of hits for the query. See Hits#length()
7 8 9 |
# File 'lib/ferret/search/top_docs.rb', line 7 def score_docs @score_docs end |
#total_hits ⇒ Object Also known as: size
Expert: The total number of hits for the query. See Hits#length()
7 8 9 |
# File 'lib/ferret/search/top_docs.rb', line 7 def total_hits @total_hits end |
Instance Method Details
#each ⇒ Object
iterate through each of the score docs, yielding the document number and the score. eg:
top_docs.each do |doc, score|
puts "Doc number #{doc} found with score of #{score}"}
end
17 18 19 |
# File 'lib/ferret/search/top_docs.rb', line 17 def each score_docs.each {|sd| yield(sd.doc, sd.score) } end |
#to_s ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/ferret/search/top_docs.rb', line 28 def to_s buffer = "#{total_hits} hits sorted by <" buffer << [fields].flatten.map {|field| "#{@field}" }.join(", ") buffer << ">:\n" score_docs.each {|sd| buffer << "\t#{sd}\n" } return buffer end |