Thumbnail file hits. Based on a patch from D Bera
[beagle.git] / beagled / Lucene.Net / Search / ScoreDocComparator.cs
blob4fa1144731b3a2e55d348e3e388973a5990427dc
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.
16 using System;
17 namespace Lucene.Net.Search
21 /// <summary> Expert: Compares two ScoreDoc objects for sorting.
22 ///
23 /// <p>Created: Feb 3, 2004 9:00:16 AM
24 ///
25 /// </summary>
26 /// <author> Tim Jones (Nacimiento Software)
27 /// </author>
28 /// <since> lucene 1.4
29 /// </since>
30 /// <version> $Id: ScoreDocComparator.cs,v 1.1 2005/01/17 19:54:30 joeshaw Exp $
31 /// </version>
32 public struct ScoreDocComparator_Fields
34 /// <summary>Special comparator for sorting hits according to computed relevance (document score). </summary>
35 public readonly static ScoreDocComparator RELEVANCE;
36 /// <summary>Special comparator for sorting hits according to index order (document number). </summary>
37 public readonly static ScoreDocComparator INDEXORDER;
38 static ScoreDocComparator_Fields()
40 RELEVANCE = new AnonymousClassScoreDocComparator();
41 INDEXORDER = new AnonymousClassScoreDocComparator1();
44 public class AnonymousClassScoreDocComparator : ScoreDocComparator
46 public virtual int Compare(ScoreDoc i, ScoreDoc j)
48 if (i.score > j.score)
49 return - 1;
50 if (i.score < j.score)
51 return 1;
52 return 0;
54 public virtual System.IComparable SortValue(ScoreDoc i)
56 return (float) i.score;
58 public virtual int SortType()
60 return SortField.SCORE;
63 public class AnonymousClassScoreDocComparator1 : ScoreDocComparator
65 public virtual int Compare(ScoreDoc i, ScoreDoc j)
67 if (i.doc < j.doc)
68 return - 1;
69 if (i.doc > j.doc)
70 return 1;
71 return 0;
73 public virtual System.IComparable SortValue(ScoreDoc i)
75 return (System.Int32) i.doc;
77 public virtual int SortType()
79 return SortField.DOC;
82 public interface ScoreDocComparator
86 /// <summary> Compares two ScoreDoc objects and returns a result indicating their
87 /// sort order.
88 /// </summary>
89 /// <param name="i">First ScoreDoc
90 /// </param>
91 /// <param name="j">Second ScoreDoc
92 /// </param>
93 /// <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
94 /// </returns>
95 /// <seealso cref="java.util.Comparator">
96 /// </seealso>
97 int Compare(ScoreDoc i, ScoreDoc j);
100 /// <summary> Returns the value used to sort the given document. The
101 /// object returned must implement the java.io.Serializable
102 /// interface. This is used by multisearchers to determine how to collate results from their searchers.
103 /// </summary>
104 /// <seealso cref="FieldDoc">
105 /// </seealso>
106 /// <param name="i">Document
107 /// </param>
108 /// <returns> Serializable object
109 /// </returns>
110 System.IComparable SortValue(ScoreDoc i);
113 /// <summary> Returns the type of sort. Should return <code>SortField.SCORE</code>, <code>SortField.DOC</code>, <code>SortField.STRING</code>, <code>SortField.INTEGER</code>,
114 /// <code>SortField.FLOAT</code> or <code>SortField.CUSTOM</code>. It is not valid to return <code>SortField.AUTO</code>.
115 /// This is used by multisearchers to determine how to collate results from their searchers.
116 /// </summary>
117 /// <returns> One of the constants in SortField.
118 /// </returns>
119 /// <seealso cref="SortField">
120 /// </seealso>
121 int SortType();