Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart9.png 37% of files have more coverage
24   97   11   4
10   50   0.46   6
6     1.83  
1    
 
  ReqOptSumScorer       Line # 25 24 11 85% 0.85
 
  (27)
 
1    package org.apache.lucene.search;
2    /**
3    * Copyright 2005 Apache Software Foundation.
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License");
6    * you may not use this file except in compliance with the License.
7    * You may obtain a copy of the License at
8    *
9    * http://www.apache.org/licenses/LICENSE-2.0
10    *
11    * Unless required by applicable law or agreed to in writing, software
12    * distributed under the License is distributed on an "AS IS" BASIS,
13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    * See the License for the specific language governing permissions and
15    * limitations under the License.
16    */
17   
18    import java.io.IOException;
19   
20    /** A Scorer for queries with a required part and an optional part.
21    * Delays skipTo() on the optional part until a score() is needed.
22    * <br>
23    * This <code>Scorer</code> implements {@link Scorer#skipTo(int)}.
24    */
 
25    public class ReqOptSumScorer extends Scorer {
26    /** The scorers passed from the constructor.
27    * These are set to null as soon as their next() or skipTo() returns false.
28    */
29    private Scorer reqScorer;
30    private Scorer optScorer;
31   
32    /** Construct a <code>ReqOptScorer</code>.
33    * @param reqScorer The required scorer. This must match.
34    * @param optScorer The optional scorer. This is used for scoring only.
35    */
 
36  9493 toggle public ReqOptSumScorer(
37    Scorer reqScorer,
38    Scorer optScorer)
39    {
40  9493 super(null); // No similarity used.
41  9493 this.reqScorer = reqScorer;
42  9493 this.optScorer = optScorer;
43    }
44   
45    private boolean firstTimeOptScorer = true;
46   
 
47  12799 toggle public boolean next() throws IOException {
48  12799 return reqScorer.next();
49    }
50   
 
51  3803 toggle public boolean skipTo(int target) throws IOException {
52  3803 return reqScorer.skipTo(target);
53    }
54   
 
55  10791 toggle public int doc() {
56  10791 return reqScorer.doc();
57    }
58   
59    /** Returns the score of the current document matching the query.
60    * Initially invalid, until {@link #next()} is called the first time.
61    * @return The score of the required scorer, eventually increased by the score
62    * of the optional scorer when it also matches the current document.
63    */
 
64  6327 toggle public float score() throws IOException {
65  6327 int curDoc = reqScorer.doc();
66  6327 float reqScore = reqScorer.score();
67  6327 if (firstTimeOptScorer) {
68  3186 firstTimeOptScorer = false;
69  3186 if (! optScorer.skipTo(curDoc)) {
70  404 optScorer = null;
71  404 return reqScore;
72    }
73  3141 } else if (optScorer == null) {
74  572 return reqScore;
75  2569 } else if ((optScorer.doc() < curDoc) && (! optScorer.skipTo(curDoc))) {
76  266 optScorer = null;
77  266 return reqScore;
78    }
79    // assert (optScorer != null) && (optScorer.doc() >= curDoc);
80  5085 return (optScorer.doc() == curDoc)
81    ? reqScore + optScorer.score()
82    : reqScore;
83    }
84   
85    /** Explain the score of a document.
86    * @todo Also show the total score.
87    * See BooleanScorer.explain() on how to do this.
88    */
 
89  0 toggle public Explanation explain(int doc) throws IOException {
90  0 Explanation res = new Explanation();
91  0 res.setDescription("required, optional");
92  0 res.addDetail(reqScorer.explain(doc));
93  0 res.addDetail(optScorer.explain(doc));
94  0 return res;
95    }
96    }
97