QueryResponses.cs, DumpIndex.cs, IQueryResult.cs, QueryExecutor.cs, QueryResult.cs...
[beagle.git] / beagled / Lucene.Net / Search / SortComparator.cs
blob115468f93321036f671c63118da99cf208e149ef
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;
18 using IndexReader = Lucene.Net.Index.IndexReader;
20 namespace Lucene.Net.Search
23 /// <summary> Abstract base class for sorting hits returned by a Query.
24 ///
25 /// <p>This class should only be used if the other SortField
26 /// types (SCORE, DOC, STRING, INT, FLOAT) do not provide an
27 /// adequate sorting. It maintains an internal cache of values which
28 /// could be quite large. The cache is an array of Comparable,
29 /// one for each document in the index. There is a distinct
30 /// Comparable for each unique term in the field - if
31 /// some documents have the same term in the field, the cache
32 /// array will have entries which reference the same Comparable.
33 ///
34 /// <p>Created: Apr 21, 2004 5:08:38 PM
35 ///
36 /// </summary>
37 /// <author> Tim Jones
38 /// </author>
39 /// <version> $Id: SortComparator.cs,v 1.3 2006/10/02 17:09:07 joeshaw Exp $
40 /// </version>
41 /// <since> 1.4
42 /// </since>
43 [Serializable]
44 public abstract class SortComparator : SortComparatorSource
46 private class AnonymousClassScoreDocComparator : ScoreDocComparator
48 public AnonymousClassScoreDocComparator(System.IComparable[] cachedValues, SortComparator enclosingInstance)
50 InitBlock(cachedValues, enclosingInstance);
52 private void InitBlock(System.IComparable[] cachedValues, SortComparator enclosingInstance)
54 this.cachedValues = cachedValues;
55 this.enclosingInstance = enclosingInstance;
57 private System.IComparable[] cachedValues;
58 private SortComparator enclosingInstance;
59 public SortComparator Enclosing_Instance
61 get
63 return enclosingInstance;
68 public virtual int Compare(ScoreDoc i, ScoreDoc j)
70 return cachedValues[i.doc].CompareTo(cachedValues[j.doc]);
73 public virtual System.IComparable SortValue(ScoreDoc i)
75 return cachedValues[i.doc];
78 public virtual int SortType()
80 return SortField.CUSTOM;
84 // inherit javadocs
85 public virtual ScoreDocComparator NewComparator(IndexReader reader, System.String fieldname)
87 System.String field = String.Intern(fieldname);
88 System.IComparable[] cachedValues = Lucene.Net.Search.FieldCache_Fields.DEFAULT.GetCustom(reader, field, this);
90 return new AnonymousClassScoreDocComparator(cachedValues, this);
93 /// <summary> Returns an object which, when sorted according to natural order,
94 /// will order the Term values in the correct order.
95 /// <p>For example, if the Terms contained integer values, this method
96 /// would return <code>new Integer(termtext)</code>. Note that this
97 /// might not always be the most efficient implementation - for this
98 /// particular example, a better implementation might be to make a
99 /// ScoreDocLookupComparator that uses an internal lookup table of int.
100 /// </summary>
101 /// <param name="termtext">The textual value of the term.
102 /// </param>
103 /// <returns> An object representing <code>termtext</code> that sorts according to the natural order of <code>termtext</code>.
104 /// </returns>
105 /// <seealso cref="Comparable">
106 /// </seealso>
107 /// <seealso cref="ScoreDocComparator">
108 /// </seealso>
109 public /*protected internal*/ abstract System.IComparable GetComparable(System.String termtext);