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.
18 using IndexReader
= Lucene
.Net
.Index
.IndexReader
;
20 namespace Lucene
.Net
.Search
23 /// <summary> Expert: Maintains caches of term values.
25 /// <p>Created: May 19, 2004 11:13:14 AM
28 /// <author> Tim Jones (Nacimiento Software)
30 /// <since> lucene 1.4
32 /// <version> $Id: FieldCache.cs,v 1.3 2006/10/02 17:09:02 joeshaw Exp $
34 /// <summary>Expert: Stores term text values and document ordering data. </summary>
35 public class StringIndex
38 /// <summary>All the term values, in natural order. </summary>
39 public System
.String
[] lookup
;
41 /// <summary>For each document, an index into the lookup array. </summary>
44 /// <summary>Creates one of these objects </summary>
45 public StringIndex(int[] values
, System
.String
[] lookup
)
51 public struct FieldCache_Fields
53 /// <summary>Indicator for StringIndex values in the cache. </summary>
54 // NOTE: the value assigned to this constant must not be
55 // the same as any of those in SortField!!
56 public readonly static int STRING_INDEX
= - 1;
57 /// <summary>Expert: The cache used internally by sorting and range query classes. </summary>
58 public readonly static FieldCache DEFAULT
;
59 static FieldCache_Fields()
61 DEFAULT
= new FieldCacheImpl();
64 public interface FieldCache
68 /// <summary>Checks the internal cache for an appropriate entry, and if none is
69 /// found, reads the terms in <code>field</code> as integers and returns an array
70 /// of size <code>reader.maxDoc()</code> of the value each document
71 /// has in the given field.
73 /// <param name="reader"> Used to get field values.
75 /// <param name="field"> Which field contains the integers.
77 /// <returns> The values in the given field for each document.
79 /// <throws> IOException If any error occurs. </throws>
80 int[] GetInts(IndexReader reader
, System
.String field
);
82 /// <summary>Checks the internal cache for an appropriate entry, and if none is found,
83 /// reads the terms in <code>field</code> as integers and returns an array of
84 /// size <code>reader.maxDoc()</code> of the value each document has in the
87 /// <param name="reader"> Used to get field values.
89 /// <param name="field"> Which field contains the integers.
91 /// <param name="parser"> Computes integer for string values.
93 /// <returns> The values in the given field for each document.
95 /// <throws> IOException If any error occurs. </throws>
96 int[] GetInts(IndexReader reader
, System
.String field
, IntParser parser
);
98 /// <summary>Checks the internal cache for an appropriate entry, and if
99 /// none is found, reads the terms in <code>field</code> as floats and returns an array
100 /// of size <code>reader.maxDoc()</code> of the value each document
101 /// has in the given field.
103 /// <param name="reader"> Used to get field values.
105 /// <param name="field"> Which field contains the floats.
107 /// <returns> The values in the given field for each document.
109 /// <throws> IOException If any error occurs. </throws>
110 float[] GetFloats(IndexReader reader
, System
.String field
);
112 /// <summary>Checks the internal cache for an appropriate entry, and if
113 /// none is found, reads the terms in <code>field</code> as floats and returns an array
114 /// of size <code>reader.maxDoc()</code> of the value each document
115 /// has in the given field.
117 /// <param name="reader"> Used to get field values.
119 /// <param name="field"> Which field contains the floats.
121 /// <param name="parser"> Computes float for string values.
123 /// <returns> The values in the given field for each document.
125 /// <throws> IOException If any error occurs. </throws>
126 float[] GetFloats(IndexReader reader
, System
.String field
, FloatParser parser
);
128 /// <summary>Checks the internal cache for an appropriate entry, and if none
129 /// is found, reads the term values in <code>field</code> and returns an array
130 /// of size <code>reader.maxDoc()</code> containing the value each document
131 /// has in the given field.
133 /// <param name="reader"> Used to get field values.
135 /// <param name="field"> Which field contains the strings.
137 /// <returns> The values in the given field for each document.
139 /// <throws> IOException If any error occurs. </throws>
140 System
.String
[] GetStrings(IndexReader reader
, System
.String field
);
142 /// <summary>Checks the internal cache for an appropriate entry, and if none
143 /// is found reads the term values in <code>field</code> and returns
144 /// an array of them in natural order, along with an array telling
145 /// which element in the term array each document uses.
147 /// <param name="reader"> Used to get field values.
149 /// <param name="field"> Which field contains the strings.
151 /// <returns> Array of terms and index into the array for each document.
153 /// <throws> IOException If any error occurs. </throws>
154 StringIndex
GetStringIndex(IndexReader reader
, System
.String field
);
156 /// <summary>Checks the internal cache for an appropriate entry, and if
157 /// none is found reads <code>field</code> to see if it contains integers, floats
158 /// or strings, and then calls one of the other methods in this class to get the
159 /// values. For string values, a StringIndex is returned. After
160 /// calling this method, there is an entry in the cache for both
161 /// type <code>AUTO</code> and the actual found type.
163 /// <param name="reader"> Used to get field values.
165 /// <param name="field"> Which field contains the values.
167 /// <returns> int[], float[] or StringIndex.
169 /// <throws> IOException If any error occurs. </throws>
170 System
.Object
GetAuto(IndexReader reader
, System
.String field
);
172 /// <summary>Checks the internal cache for an appropriate entry, and if none
173 /// is found reads the terms out of <code>field</code> and calls the given SortComparator
174 /// to get the sort values. A hit in the cache will happen if <code>reader</code>,
175 /// <code>field</code>, and <code>comparator</code> are the same (using <code>equals()</code>)
176 /// as a previous call to this method.
178 /// <param name="reader"> Used to get field values.
180 /// <param name="field"> Which field contains the values.
182 /// <param name="comparator">Used to convert terms into something to sort by.
184 /// <returns> Array of sort objects, one for each document.
186 /// <throws> IOException If any error occurs. </throws>
187 System
.IComparable
[] GetCustom(IndexReader reader
, System
.String field
, SortComparator comparator
);
190 /// <summary>Interface to parse ints from document fields.</summary>
191 /// <seealso cref="GetInts(IndexReader, String, IntParser)">
193 public interface IntParser
195 /// <summary>Return an integer representation of this field's value. </summary>
196 int ParseInt(System
.String string_Renamed
);
199 /// <summary>Interface to parse floats from document fields.</summary>
200 /// <seealso cref="GetFloats(IndexReader, String, FloatParser)">
202 public interface FloatParser
204 /// <summary>Return an float representation of this field's value. </summary>
205 float ParseFloat(System
.String string_Renamed
);