KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > ScoreDocComparator


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         public int compare (ScoreDoc i, ScoreDoc j) {
34             if (i.score > j.score) return -1;
35             if (i.score < j.score) return 1;
36             return 0;
37         }
38         public Comparable JavaDoc sortValue (ScoreDoc i) {
39             return new Float JavaDoc (i.score);
40         }
41         public int sortType() {
42             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         public int compare (ScoreDoc i, ScoreDoc j) {
50             if (i.doc < j.doc) return -1;
51             if (i.doc > j.doc) return 1;
52             return 0;
53         }
54         public Comparable JavaDoc sortValue (ScoreDoc i) {
55             return new Integer JavaDoc (i.doc);
56         }
57         public int sortType() {
58             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 JavaDoc 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 }
Popular Tags