QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / ScoreDocComparator.cs
blob679b804000697c9d036250eb184b10628f1ac007
1 /*
2 * Copyright 2004 The Apache Software Foundation
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
17 using System;
19 namespace Lucene.Net.Search
23 /// <summary> Expert: Compares two ScoreDoc objects for sorting.
24 ///
25 /// <p>Created: Feb 3, 2004 9:00:16 AM
26 ///
27 /// </summary>
28 /// <author> Tim Jones (Nacimiento Software)
29 /// </author>
30 /// <since> lucene 1.4
31 /// </since>
32 /// <version> $Id: ScoreDocComparator.cs,v 1.3 2006/10/02 17:09:07 joeshaw Exp $
33 /// </version>
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)
51 return - 1;
52 if (i.score < j.score)
53 return 1;
54 return 0;
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)
69 if (i.doc < j.doc)
70 return - 1;
71 if (i.doc > j.doc)
72 return 1;
73 return 0;
75 public virtual System.IComparable SortValue(ScoreDoc i)
77 return (System.Int32) i.doc;
79 public virtual int SortType()
81 return SortField.DOC;
84 public interface ScoreDocComparator
88 /// <summary> Compares two ScoreDoc objects and returns a result indicating their
89 /// sort order.
90 /// </summary>
91 /// <param name="i">First ScoreDoc
92 /// </param>
93 /// <param name="j">Second ScoreDoc
94 /// </param>
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
96 /// </returns>
97 /// <seealso cref="java.util.Comparator">
98 /// </seealso>
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.
105 /// </summary>
106 /// <seealso cref="FieldDoc">
107 /// </seealso>
108 /// <param name="i">Document
109 /// </param>
110 /// <returns> Serializable object
111 /// </returns>
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.
118 /// </summary>
119 /// <returns> One of the constants in SortField.
120 /// </returns>
121 /// <seealso cref="SortField">
122 /// </seealso>
123 int SortType();