Class: Ferret::Search::Scorer
- Inherits:
-
Object
- Object
- Ferret::Search::Scorer
- Defined in:
- lib/ferret/search/scorer.rb
Overview
Expert: Common scoring functionality for different types of queries.
A Scorer either iterates over documents matching a query, or provides an explanation of the score for a query for a given document.
Document scores are computed using a given Similarity implementation.
Direct Known Subclasses
ConjunctionScorer, DisjunctionSumScorer, FilteredQuery::FilteredScorer, MatchAllDocsQuery::MatchAllScorer, NonMatchingScorer, PhraseScorer, ReqExclScorer, ReqOptSumScorer, Ferret::Search::Spans::SpanScorer, TermScorer
Constant Summary collapse
- MAX_DOCS =
0x7FFFFFFF
Instance Attribute Summary collapse
-
#similarity ⇒ Object
readonly
Returns the value of attribute similarity.
Instance Method Summary collapse
-
#doc ⇒ Object
Returns the current document number matching the query.
-
#each_hit ⇒ Object
Expert: Iterates over matching all documents, yielding the document number and the score.
-
#each_hit_up_to(max = MAX_DOCS) ⇒ Object
Expert: Iterates over matching documents in a range.
-
#explain(doc) ⇒ Object
Returns an explanation of the score for a document.
-
#initialize(similarity) ⇒ Scorer
constructor
Constructs a Scorer.
-
#next? ⇒ Boolean
Advances to the next document matching the query.
-
#score ⇒ Object
Returns the score for the current document matching the query.
-
#skip_to(target) ⇒ Object
Skips to the first match beyond the current whose document number is greater than or equal to a given target.
Constructor Details
#initialize(similarity) ⇒ Scorer
Constructs a Scorer.
- similarity
-
The
Similarityimplementation used by this scorer.
14 15 16 |
# File 'lib/ferret/search/scorer.rb', line 14 def initialize(similarity) @similarity = similarity end |
Instance Attribute Details
#similarity ⇒ Object (readonly)
Returns the value of attribute similarity.
9 10 11 |
# File 'lib/ferret/search/scorer.rb', line 9 def similarity @similarity end |
Instance Method Details
#doc ⇒ Object
Returns the current document number matching the query. Initially invalid, until #next?() is called the first time.
49 50 51 |
# File 'lib/ferret/search/scorer.rb', line 49 def doc() raise NotImplementedError end |
#each_hit ⇒ Object
Expert: Iterates over matching all documents, yielding the document number and the score.
- returns
-
true if more matching documents may remain.
22 23 24 25 26 |
# File 'lib/ferret/search/scorer.rb', line 22 def each_hit() # :yields: doc, score while next? yield(doc(), score()) end end |
#each_hit_up_to(max = MAX_DOCS) ⇒ Object
Expert: Iterates over matching documents in a range.
- max
-
Do not score documents past this. Default will search all documents
avaliable.
- returns
-
true if more matching documents may remain.
33 34 35 36 37 38 |
# File 'lib/ferret/search/scorer.rb', line 33 def each_hit_up_to(max = MAX_DOCS) # :yields: doc, score while (next? and doc() < max) yield(doc(), score()) end return doc() < max end |
#explain(doc) ⇒ Object
Returns an explanation of the score for a document.
When this method is used, the #next?(), #skip_to(int) and #score(HitCollector) methods should not be used.
- doc
-
The document number for the explanation.
87 88 89 |
# File 'lib/ferret/search/scorer.rb', line 87 def explain(doc) raise NotImplementedError end |
#next? ⇒ Boolean
Advances to the next document matching the query.
- returns
-
true iff there is another document matching the query.
When this method is used the #explain(int) method should not be used.
43 44 45 |
# File 'lib/ferret/search/scorer.rb', line 43 def next?() raise NotImplementedError end |
#score ⇒ Object
Returns the score for the current document matching the query. Initially invalid, until #next?() is called the first time.
55 56 57 |
# File 'lib/ferret/search/scorer.rb', line 55 def score() raise NotImplementedError end |
#skip_to(target) ⇒ Object
Skips to the first match beyond the current whose document number is greater than or equal to a given target.
When this method is used the #explain(int) method should not be used.
- target
-
The target document number.
- returns
-
true iff there is such a match.
Behaves as if written:
def skip_to(target)
begin
return false if not next?()
end while (target > doc())
return true
end
Most implementations are considerably more efficient than that.
77 78 79 |
# File 'lib/ferret/search/scorer.rb', line 77 def skip_to(target) raise NotImplementedError end |