KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > FieldCache


1 package org.apache.lucene.search;
2
3 /**
4  * Copyright 2004 The Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.lucene.index.IndexReader;
20 import java.io.IOException JavaDoc;
21
22 /**
23  * Expert: Maintains caches of term values.
24  *
25  * <p>Created: May 19, 2004 11:13:14 AM
26  *
27  * @author Tim Jones (Nacimiento Software)
28  * @since lucene 1.4
29  * @version $Id: FieldCache.java 179605 2005-06-02 16:48:40Z cutting $
30  */

31 public interface FieldCache {
32
33   /** Indicator for StringIndex values in the cache. */
34   // NOTE: the value assigned to this constant must not be
35
// the same as any of those in SortField!!
36
public static final int STRING_INDEX = -1;
37
38
39   /** Expert: Stores term text values and document ordering data. */
40   public static class StringIndex {
41
42     /** All the term values, in natural order. */
43     public final String JavaDoc[] lookup;
44
45     /** For each document, an index into the lookup array. */
46     public final int[] order;
47
48     /** Creates one of these objects */
49     public StringIndex (int[] values, String JavaDoc[] lookup) {
50       this.order = values;
51       this.lookup = lookup;
52     }
53   }
54
55   /** Interface to parse ints from document fields.
56    * @see #getInts(IndexReader, String, IntParser)
57    */

58   public interface IntParser {
59     /** Return an integer representation of this field's value. */
60     public int parseInt(String JavaDoc string);
61   }
62
63
64   /** Interface to parse floats from document fields.
65    * @see #getFloats(IndexReader, String, FloatParser)
66    */

67   public interface FloatParser {
68     /** Return an float representation of this field's value. */
69     public float parseFloat(String JavaDoc string);
70   }
71
72   /** Expert: The cache used internally by sorting and range query classes. */
73   public static FieldCache DEFAULT = new FieldCacheImpl();
74
75
76   /** Checks the internal cache for an appropriate entry, and if none is
77    * found, reads the terms in <code>field</code> as integers and returns an array
78    * of size <code>reader.maxDoc()</code> of the value each document
79    * has in the given field.
80    * @param reader Used to get field values.
81    * @param field Which field contains the integers.
82    * @return The values in the given field for each document.
83    * @throws IOException If any error occurs.
84    */

85   public int[] getInts (IndexReader reader, String JavaDoc field)
86   throws IOException JavaDoc;
87
88   /** Checks the internal cache for an appropriate entry, and if none is found,
89    * reads the terms in <code>field</code> as integers and returns an array of
90    * size <code>reader.maxDoc()</code> of the value each document has in the
91    * given field.
92    * @param reader Used to get field values.
93    * @param field Which field contains the integers.
94    * @param parser Computes integer for string values.
95    * @return The values in the given field for each document.
96    * @throws IOException If any error occurs.
97    */

98   public int[] getInts (IndexReader reader, String JavaDoc field, IntParser parser)
99   throws IOException JavaDoc;
100
101   /** Checks the internal cache for an appropriate entry, and if
102    * none is found, reads the terms in <code>field</code> as floats and returns an array
103    * of size <code>reader.maxDoc()</code> of the value each document
104    * has in the given field.
105    * @param reader Used to get field values.
106    * @param field Which field contains the floats.
107    * @return The values in the given field for each document.
108    * @throws IOException If any error occurs.
109    */

110   public float[] getFloats (IndexReader reader, String JavaDoc field)
111   throws IOException JavaDoc;
112
113   /** Checks the internal cache for an appropriate entry, and if
114    * none is found, reads the terms in <code>field</code> as floats and returns an array
115    * of size <code>reader.maxDoc()</code> of the value each document
116    * has in the given field.
117    * @param reader Used to get field values.
118    * @param field Which field contains the floats.
119    * @param parser Computes float for string values.
120    * @return The values in the given field for each document.
121    * @throws IOException If any error occurs.
122    */

123   public float[] getFloats (IndexReader reader, String JavaDoc field,
124                             FloatParser parser) throws IOException JavaDoc;
125
126   /** Checks the internal cache for an appropriate entry, and if none
127    * is found, reads the term values in <code>field</code> and returns an array
128    * of size <code>reader.maxDoc()</code> containing the value each document
129    * has in the given field.
130    * @param reader Used to get field values.
131    * @param field Which field contains the strings.
132    * @return The values in the given field for each document.
133    * @throws IOException If any error occurs.
134    */

135   public String JavaDoc[] getStrings (IndexReader reader, String JavaDoc field)
136   throws IOException JavaDoc;
137
138   /** Checks the internal cache for an appropriate entry, and if none
139    * is found reads the term values in <code>field</code> and returns
140    * an array of them in natural order, along with an array telling
141    * which element in the term array each document uses.
142    * @param reader Used to get field values.
143    * @param field Which field contains the strings.
144    * @return Array of terms and index into the array for each document.
145    * @throws IOException If any error occurs.
146    */

147   public StringIndex getStringIndex (IndexReader reader, String JavaDoc field)
148   throws IOException JavaDoc;
149
150   /** Checks the internal cache for an appropriate entry, and if
151    * none is found reads <code>field</code> to see if it contains integers, floats
152    * or strings, and then calls one of the other methods in this class to get the
153    * values. For string values, a StringIndex is returned. After
154    * calling this method, there is an entry in the cache for both
155    * type <code>AUTO</code> and the actual found type.
156    * @param reader Used to get field values.
157    * @param field Which field contains the values.
158    * @return int[], float[] or StringIndex.
159    * @throws IOException If any error occurs.
160    */

161   public Object JavaDoc getAuto (IndexReader reader, String JavaDoc field)
162   throws IOException JavaDoc;
163
164   /** Checks the internal cache for an appropriate entry, and if none
165    * is found reads the terms out of <code>field</code> and calls the given SortComparator
166    * to get the sort values. A hit in the cache will happen if <code>reader</code>,
167    * <code>field</code>, and <code>comparator</code> are the same (using <code>equals()</code>)
168    * as a previous call to this method.
169    * @param reader Used to get field values.
170    * @param field Which field contains the values.
171    * @param comparator Used to convert terms into something to sort by.
172    * @return Array of sort objects, one for each document.
173    * @throws IOException If any error occurs.
174    */

175   public Comparable JavaDoc[] getCustom (IndexReader reader, String JavaDoc field, SortComparator comparator)
176   throws IOException JavaDoc;
177 }
178
Popular Tags