001: package org.apache.lucene.search;
002:
003: /**
004: * Licensed to the Apache Software Foundation (ASF) under one or more
005: * contributor license agreements. See the NOTICE file distributed with
006: * this work for additional information regarding copyright ownership.
007: * The ASF licenses this file to You under the Apache License, Version 2.0
008: * (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: */
019:
020: /**
021: * Expert: Compares two ScoreDoc objects for sorting.
022: *
023: * <p>Created: Feb 3, 2004 9:00:16 AM
024: *
025: * @author Tim Jones (Nacimiento Software)
026: * @since lucene 1.4
027: * @version $Id: ScoreDocComparator.java 518518 2007-03-15 08:48:00Z buschmi $
028: */
029: public interface ScoreDocComparator {
030:
031: /** Special comparator for sorting hits according to computed relevance (document score). */
032: static final ScoreDocComparator RELEVANCE = new ScoreDocComparator() {
033: public int compare(ScoreDoc i, ScoreDoc j) {
034: if (i.score > j.score)
035: return -1;
036: if (i.score < j.score)
037: return 1;
038: return 0;
039: }
040:
041: public Comparable sortValue(ScoreDoc i) {
042: return new Float(i.score);
043: }
044:
045: public int sortType() {
046: return SortField.SCORE;
047: }
048: };
049:
050: /** Special comparator for sorting hits according to index order (document number). */
051: static final ScoreDocComparator INDEXORDER = new ScoreDocComparator() {
052: public int compare(ScoreDoc i, ScoreDoc j) {
053: if (i.doc < j.doc)
054: return -1;
055: if (i.doc > j.doc)
056: return 1;
057: return 0;
058: }
059:
060: public Comparable sortValue(ScoreDoc i) {
061: return new Integer(i.doc);
062: }
063:
064: public int sortType() {
065: return SortField.DOC;
066: }
067: };
068:
069: /**
070: * Compares two ScoreDoc objects and returns a result indicating their
071: * sort order.
072: * @param i First ScoreDoc
073: * @param j Second ScoreDoc
074: * @return a negative integer if <code>i</code> should come before <code>j</code><br>
075: * a positive integer if <code>i</code> should come after <code>j</code><br>
076: * <code>0</code> if they are equal
077: * @see java.util.Comparator
078: */
079: int compare(ScoreDoc i, ScoreDoc j);
080:
081: /**
082: * Returns the value used to sort the given document. The
083: * object returned must implement the java.io.Serializable
084: * interface. This is used by multisearchers to determine how
085: * to collate results from their searchers.
086: * @see FieldDoc
087: * @param i Document
088: * @return Serializable object
089: */
090: Comparable sortValue(ScoreDoc i);
091:
092: /**
093: * Returns the type of sort. Should return <code>SortField.SCORE</code>,
094: * <code>SortField.DOC</code>, <code>SortField.STRING</code>,
095: * <code>SortField.INTEGER</code>, <code>SortField.FLOAT</code> or
096: * <code>SortField.CUSTOM</code>. It is not valid to return
097: * <code>SortField.AUTO</code>.
098: * This is used by multisearchers to determine how to collate results
099: * from their searchers.
100: * @return One of the constants in SortField.
101: * @see SortField
102: */
103: int sortType();
104: }
|