Class: Ferret::Search::ReqOptSumScorer
- Defined in:
- lib/ferret/search/req_opt_sum_scorer.rb
Overview
A Scorer for queries with a required part and an optional part. Delays skip_to() on the optional part until a score() is needed.
This Scorer
implements Scorer#skip_to(int).
Constant Summary
Constants inherited from Scorer
Instance Attribute Summary
Attributes inherited from Scorer
Instance Method Summary collapse
- #doc ⇒ Object
-
#explain(doc) ⇒ Object
Explain the score of a document.
-
#initialize(req_scorer, opt_scorer) ⇒ ReqOptSumScorer
constructor
The scorers passed from the constructor.
- #next? ⇒ Boolean
-
#score ⇒ Object
Returns the score of the current document matching the query.
- #skip_to(target) ⇒ Object
Methods inherited from Scorer
Constructor Details
#initialize(req_scorer, opt_scorer) ⇒ ReqOptSumScorer
The scorers passed from the constructor. These are set to nil as soon as their next? or skip_to() returns false.
Construct a ReqOptScorer
.
- req_scorer
-
The required scorer. This must match.
- opt_scorer
-
The optional scorer. This is used for scoring only.
13 14 15 16 17 18 19 |
# File 'lib/ferret/search/req_opt_sum_scorer.rb', line 13 def initialize(req_scorer, opt_scorer) super(nil) # No similarity used. @req_scorer = req_scorer @opt_scorer = opt_scorer @first_time_opt_scorer = true end |
Instance Method Details
#doc ⇒ Object
30 31 32 |
# File 'lib/ferret/search/req_opt_sum_scorer.rb', line 30 def doc() return @req_scorer.doc() end |
#explain(doc) ⇒ Object
Also show the total score.
Explain the score of a document. See BooleanScorer.explain() on how to do this.
62 63 64 65 66 67 68 |
# File 'lib/ferret/search/req_opt_sum_scorer.rb', line 62 def explain(doc) e = Explanation.new() e.description = "required, optional" e.details << @req_scorer.explain(doc) e.details << @opt_scorer.explain(doc) return e end |
#next? ⇒ Boolean
22 23 24 |
# File 'lib/ferret/search/req_opt_sum_scorer.rb', line 22 def next? return @req_scorer.next? end |
#score ⇒ Object
Returns the score of the current document matching the query. Initially invalid, until #next? is called the first time.
- returns
-
The score of the required scorer, eventually increased by the score of the optional scorer when it also matches the current document.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ferret/search/req_opt_sum_scorer.rb', line 40 def score() cur_doc = @req_scorer.doc req_score = @req_scorer.score if @first_time_opt_scorer @first_time_opt_scorer = false if not @opt_scorer.skip_to(cur_doc) @opt_scorer = nil return req_score end elsif @opt_scorer.nil? return req_score elsif @opt_scorer.doc < cur_doc and not @opt_scorer.skip_to(cur_doc) @opt_scorer = nil return req_score end # assert (@opt_scorer != nil) and (@opt_scorer.doc() >= cur_doc) return (@opt_scorer.doc == cur_doc) ? req_score + @opt_scorer.score() : req_score end |
#skip_to(target) ⇒ Object
26 27 28 |
# File 'lib/ferret/search/req_opt_sum_scorer.rb', line 26 def skip_to(target) return @req_scorer.skip_to(target) end |