Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / tools / monkeydoc / Lucene.Net / Lucene.Net / Search / ScoreDocComparator.cs
1 /* 
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  * 
9  * http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 using System;
19
20 namespace Mono.Lucene.Net.Search
21 {
22         
23         /// <summary> Expert: Compares two ScoreDoc objects for sorting.
24         /// 
25         /// <p/>Created: Feb 3, 2004 9:00:16 AM 
26         /// 
27         /// </summary>
28         /// <since>   lucene 1.4
29         /// </since>
30         /// <version>  $Id: ScoreDocComparator.java 738219 2009-01-27 20:15:21Z mikemccand $
31         /// </version>
32         /// <deprecated> use {@link FieldComparator}
33         /// </deprecated>
34     [Obsolete("use FieldComparator")]
35         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()
41                 {
42                         RELEVANCE = new AnonymousClassScoreDocComparator();
43                         INDEXORDER = new AnonymousClassScoreDocComparator1();
44                 }
45         }
46         class AnonymousClassScoreDocComparator : ScoreDocComparator
47         {
48                 public virtual int Compare(ScoreDoc i, ScoreDoc j)
49                 {
50                         if (i.score > j.score)
51                                 return - 1;
52                         if (i.score < j.score)
53                                 return 1;
54                         return 0;
55                 }
56                 public virtual System.IComparable SortValue(ScoreDoc i)
57                 {
58                         return (float) i.score;
59                 }
60                 public virtual int SortType()
61                 {
62                         return SortField.SCORE;
63                 }
64         }
65         class AnonymousClassScoreDocComparator1 : ScoreDocComparator
66         {
67                 public virtual int Compare(ScoreDoc i, ScoreDoc j)
68                 {
69                         if (i.doc < j.doc)
70                                 return - 1;
71                         if (i.doc > j.doc)
72                                 return 1;
73                         return 0;
74                 }
75                 public virtual System.IComparable SortValue(ScoreDoc i)
76                 {
77                         return (System.Int32) i.doc;
78                 }
79                 public virtual int SortType()
80                 {
81                         return SortField.DOC;
82                 }
83         }
84         public interface ScoreDocComparator
85         {
86                 
87                 /// <summary> Compares two ScoreDoc objects and returns a result indicating their
88                 /// sort order.
89                 /// </summary>
90                 /// <param name="i">First ScoreDoc
91                 /// </param>
92                 /// <param name="j">Second ScoreDoc
93                 /// </param>
94                 /// <returns> a negative integer if <code>i</code> should come before <code>j</code><br/>
95                 /// a positive integer if <code>i</code> should come after <code>j</code><br/>
96                 /// <code>0</code> if they are equal
97                 /// </returns>
98                 /// <seealso cref="java.util.Comparator">
99                 /// </seealso>
100                 int Compare(ScoreDoc i, ScoreDoc j);
101                 
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
105                 /// to collate results from their searchers.
106                 /// </summary>
107                 /// <seealso cref="FieldDoc">
108                 /// </seealso>
109                 /// <param name="i">Document
110                 /// </param>
111                 /// <returns> Serializable object
112                 /// </returns>
113                 System.IComparable SortValue(ScoreDoc i);
114                 
115                 /// <summary> Returns the type of sort.  Should return <code>SortField.SCORE</code>,
116                 /// <code>SortField.DOC</code>, <code>SortField.STRING</code>,
117                 /// <code>SortField.INTEGER</code>, <code>SortField.FLOAT</code> or
118                 /// <code>SortField.CUSTOM</code>.  It is not valid to return
119                 /// <code>SortField.AUTO</code>.
120                 /// This is used by multisearchers to determine how to collate results
121                 /// from their searchers.
122                 /// </summary>
123                 /// <returns> One of the constants in SortField.
124                 /// </returns>
125                 /// <seealso cref="SortField">
126                 /// </seealso>
127                 int SortType();
128         }
129 }