FieldCache.java
001 package gate.creole.annic.apache.lucene.search;
002 
003 /**
004  * Copyright 2004 The Apache Software Foundation
005  *
006  * Licensed under the Apache License, Version 2.0 (the "License");
007  * you may not use this file except in compliance with the License.
008  * You may obtain a copy of the License at
009  *
010  *     http://www.apache.org/licenses/LICENSE-2.0
011  *
012  * Unless required by applicable law or agreed to in writing, software
013  * distributed under the License is distributed on an "AS IS" BASIS,
014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015  * See the License for the specific language governing permissions and
016  * limitations under the License.
017  */
018 
019 import gate.creole.annic.apache.lucene.index.IndexReader;
020 import java.io.IOException;
021 
022 /**
023  * Expert: Maintains caches of term values.
024  *
025  <p>Created: May 19, 2004 11:13:14 AM
026  *
027  @author  Tim Jones (Nacimiento Software)
028  @since   lucene 1.4
029  @version $Id: FieldCache.java 529 2004-10-05 11:55:26Z niraj $
030  */
031 public interface FieldCache {
032 
033   /** Indicator for StringIndex values in the cache. */
034   // NOTE: the value assigned to this constant must not be
035   // the same as any of those in SortField!!
036   public static final int STRING_INDEX = -1;
037 
038 
039   /** Expert: Stores term text values and document ordering data. */
040   public static class StringIndex {
041 
042     /** All the term values, in natural order. */
043     public final String[] lookup;
044 
045     /** For each document, an index into the lookup array. */
046     public final int[] order;
047 
048     /** Creates one of these objects */
049     public StringIndex (int[] values, String[] lookup) {
050       this.order = values;
051       this.lookup = lookup;
052     }
053   }
054 
055 
056   /** Expert: The cache used internally by sorting and range query classes. */
057   public static FieldCache DEFAULT = new FieldCacheImpl();
058 
059 
060   /** Checks the internal cache for an appropriate entry, and if none is
061    * found, reads the terms in <code>field</code> as integers and returns an array
062    * of size <code>reader.maxDoc()</code> of the value each document
063    * has in the given field.
064    @param reader  Used to get field values.
065    @param field   Which field contains the integers.
066    @return The values in the given field for each document.
067    @throws IOException  If any error occurs.
068    */
069   public int[] getInts (IndexReader reader, String field)
070   throws IOException;
071 
072   /** Checks the internal cache for an appropriate entry, and if
073    * none is found, reads the terms in <code>field</code> as floats and returns an array
074    * of size <code>reader.maxDoc()</code> of the value each document
075    * has in the given field.
076    @param reader  Used to get field values.
077    @param field   Which field contains the floats.
078    @return The values in the given field for each document.
079    @throws IOException  If any error occurs.
080    */
081   public float[] getFloats (IndexReader reader, String field)
082   throws IOException;
083 
084   /** Checks the internal cache for an appropriate entry, and if none
085    * is found, reads the term values in <code>field</code> and returns an array
086    * of size <code>reader.maxDoc()</code> containing the value each document
087    * has in the given field.
088    @param reader  Used to get field values.
089    @param field   Which field contains the strings.
090    @return The values in the given field for each document.
091    @throws IOException  If any error occurs.
092    */
093   public String[] getStrings (IndexReader reader, String field)
094   throws IOException;
095 
096   /** Checks the internal cache for an appropriate entry, and if none
097    * is found reads the term values in <code>field</code> and returns
098    * an array of them in natural order, along with an array telling
099    * which element in the term array each document uses.
100    @param reader  Used to get field values.
101    @param field   Which field contains the strings.
102    @return Array of terms and index into the array for each document.
103    @throws IOException  If any error occurs.
104    */
105   public StringIndex getStringIndex (IndexReader reader, String field)
106   throws IOException;
107 
108   /** Checks the internal cache for an appropriate entry, and if
109    * none is found reads <code>field</code> to see if it contains integers, floats
110    * or strings, and then calls one of the other methods in this class to get the
111    * values.  For string values, a StringIndex is returned.  After
112    * calling this method, there is an entry in the cache for both
113    * type <code>AUTO</code> and the actual found type.
114    @param reader  Used to get field values.
115    @param field   Which field contains the values.
116    @return int[], float[] or StringIndex.
117    @throws IOException  If any error occurs.
118    */
119   public Object getAuto (IndexReader reader, String field)
120   throws IOException;
121 
122   /** Checks the internal cache for an appropriate entry, and if none
123    * is found reads the terms out of <code>field</code> and calls the given SortComparator
124    * to get the sort values.  A hit in the cache will happen if <code>reader</code>,
125    <code>field</code>, and <code>comparator</code> are the same (using <code>equals()</code>)
126    * as a previous call to this method.
127    @param reader  Used to get field values.
128    @param field   Which field contains the values.
129    @param comparator Used to convert terms into something to sort by.
130    @return Array of sort objects, one for each document.
131    @throws IOException  If any error occurs.
132    */
133   public Comparable[] getCustom (IndexReader reader, String field, SortComparator comparator)
134   throws IOException;
135 }