2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Lucene
.Net
.Search
23 /// <summary> Expert: Compares two ScoreDoc objects for sorting.
25 /// <p>Created: Feb 3, 2004 9:00:16 AM
28 /// <author> Tim Jones (Nacimiento Software)
30 /// <since> lucene 1.4
32 /// <version> $Id: ScoreDocComparator.cs,v 1.3 2006/10/02 17:09:07 joeshaw Exp $
34 public struct ScoreDocComparator_Fields
36 /// <summary>Special comparator for sorting hits according to computed relevance (document score). </summary>
37 public readonly static ScoreDocComparator RELEVANCE
;
38 /// <summary>Special comparator for sorting hits according to index order (document number). </summary>
39 public readonly static ScoreDocComparator INDEXORDER
;
40 static ScoreDocComparator_Fields()
42 RELEVANCE
= new AnonymousClassScoreDocComparator();
43 INDEXORDER
= new AnonymousClassScoreDocComparator1();
46 public class AnonymousClassScoreDocComparator
: ScoreDocComparator
48 public virtual int Compare(ScoreDoc i
, ScoreDoc j
)
50 if (i
.score
> j
.score
)
52 if (i
.score
< j
.score
)
56 public virtual System
.IComparable
SortValue(ScoreDoc i
)
58 return (float) i
.score
;
60 public virtual int SortType()
62 return SortField
.SCORE
;
65 public class AnonymousClassScoreDocComparator1
: ScoreDocComparator
67 public virtual int Compare(ScoreDoc i
, ScoreDoc j
)
75 public virtual System
.IComparable
SortValue(ScoreDoc i
)
77 return (System
.Int32
) i
.doc
;
79 public virtual int SortType()
84 public interface ScoreDocComparator
88 /// <summary> Compares two ScoreDoc objects and returns a result indicating their
91 /// <param name="i">First ScoreDoc
93 /// <param name="j">Second ScoreDoc
95 /// <returns> <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
97 /// <seealso cref="java.util.Comparator">
99 int Compare(ScoreDoc i
, ScoreDoc j
);
102 /// <summary> Returns the value used to sort the given document. The
103 /// object returned must implement the java.io.Serializable
104 /// interface. This is used by multisearchers to determine how to collate results from their searchers.
106 /// <seealso cref="FieldDoc">
108 /// <param name="i">Document
110 /// <returns> Serializable object
112 System
.IComparable
SortValue(ScoreDoc i
);
115 /// <summary> Returns the type of sort. Should return <code>SortField.SCORE</code>, <code>SortField.DOC</code>, <code>SortField.STRING</code>, <code>SortField.INTEGER</code>,
116 /// <code>SortField.FLOAT</code> or <code>SortField.CUSTOM</code>. It is not valid to return <code>SortField.AUTO</code>.
117 /// This is used by multisearchers to determine how to collate results from their searchers.
119 /// <returns> One of the constants in SortField.
121 /// <seealso cref="SortField">