Clover Coverage Report
Coverage timestamp: Fri May 9 2008 10:54:27 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
14   93   10   2.33
8   31   0.71   6
6     1.67  
1    
 
  ScoreDocComparator       Line # 29 14 10 92.9% 0.9285714
 
  (19)
 
1    package org.apache.lucene.search;
2   
3    /**
4    * Copyright 2004 The Apache Software Foundation
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10    * http://www.apache.org/licenses/LICENSE-2.0
11    *
12    * Unless required by applicable law or agreed to in writing, software
13    * distributed under the License is distributed on an "AS IS" BASIS,
14    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    * See the License for the specific language governing permissions and
16    * limitations under the License.
17    */
18   
19   
20    /**
21    * Expert: Compares two ScoreDoc objects for sorting.
22    *
23    * <p>Created: Feb 3, 2004 9:00:16 AM
24    *
25    * @author Tim Jones (Nacimiento Software)
26    * @since lucene 1.4
27    * @version $Id: ScoreDocComparator.java 150348 2004-05-19 23:05:27Z tjones $
28    */
 
29    public interface ScoreDocComparator {
30   
31    /** Special comparator for sorting hits according to computed relevance (document score). */
32    static final ScoreDocComparator RELEVANCE = new ScoreDocComparator() {
 
33  12629 toggle public int compare (ScoreDoc i, ScoreDoc j) {
34  12629 if (i.score > j.score) return -1;
35  12563 if (i.score < j.score) return 1;
36  12453 return 0;
37    }
 
38  3003 toggle public Comparable sortValue (ScoreDoc i) {
39  3003 return new Float (i.score);
40    }
 
41  74 toggle public int sortType() {
42  74 return SortField.SCORE;
43    }
44    };
45   
46   
47    /** Special comparator for sorting hits according to index order (document number). */
48    static final ScoreDocComparator INDEXORDER = new ScoreDocComparator() {
 
49  3708 toggle public int compare (ScoreDoc i, ScoreDoc j) {
50  3708 if (i.doc < j.doc) return -1;
51  2090 if (i.doc > j.doc) return 1;
52  0 return 0;
53    }
 
54  3626 toggle public Comparable sortValue (ScoreDoc i) {
55  3626 return new Integer (i.doc);
56    }
 
57  4372 toggle public int sortType() {
58  4372 return SortField.DOC;
59    }
60    };
61   
62   
63    /**
64    * Compares two ScoreDoc objects and returns a result indicating their
65    * sort order.
66    * @param i First ScoreDoc
67    * @param j Second ScoreDoc
68    * @return <code>-1</code> if <code>i</code> should come before <code>j</code><br><code>1</code> if <code>i</code> should come after <code>j</code><br><code>0</code> if they are equal
69    * @see java.util.Comparator
70    */
71    int compare (ScoreDoc i, ScoreDoc j);
72   
73   
74    /**
75    * Returns the value used to sort the given document. The
76    * object returned must implement the java.io.Serializable
77    * interface. This is used by multisearchers to determine how to collate results from their searchers.
78    * @see FieldDoc
79    * @param i Document
80    * @return Serializable object
81    */
82    Comparable sortValue (ScoreDoc i);
83   
84   
85    /**
86    * Returns the type of sort. Should return <code>SortField.SCORE</code>, <code>SortField.DOC</code>, <code>SortField.STRING</code>, <code>SortField.INTEGER</code>,
87    * <code>SortField.FLOAT</code> or <code>SortField.CUSTOM</code>. It is not valid to return <code>SortField.AUTO</code>.
88    * This is used by multisearchers to determine how to collate results from their searchers.
89    * @return One of the constants in SortField.
90    * @see SortField
91    */
92    int sortType();
93    }