gate.creole.annic.apache.lucene.search
Class FieldCacheImpl

java.lang.Object
  extended by gate.creole.annic.apache.lucene.search.FieldCacheImpl
All Implemented Interfaces:
FieldCache

 class FieldCacheImpl
extends Object
implements FieldCache

Expert: The default cache implementation, storing all values in memory. A WeakHashMap is used for storage.

Created: May 19, 2004 4:40:36 PM

Since:
lucene 1.4
Version:
$Id: FieldCacheImpl.java 529 2004-10-05 11:55:26Z niraj $
Author:
Tim Jones (Nacimiento Software)

Nested Class Summary
(package private) static class FieldCacheImpl.Entry
          Expert: Every key in the internal cache is of this type.
 
Nested classes/interfaces inherited from interface gate.creole.annic.apache.lucene.search.FieldCache
FieldCache.StringIndex
 
Field Summary
(package private)  Map cache
          The internal cache.
 
Fields inherited from interface gate.creole.annic.apache.lucene.search.FieldCache
DEFAULT, STRING_INDEX
 
Constructor Summary
FieldCacheImpl()
           
 
Method Summary
 Object getAuto(IndexReader reader, String field)
          removed for java 1.3 compatibility protected static final Object pFloats = Pattern.compile ("[0-9+\\-\\.eEfFdD]+");
 Comparable[] getCustom(IndexReader reader, String field, SortComparator comparator)
          Checks the internal cache for an appropriate entry, and if none is found reads the terms out of field and calls the given SortComparator to get the sort values.
 float[] getFloats(IndexReader reader, String field)
          Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as floats and returns an array of size reader.maxDoc() of the value each document has in the given field.
 int[] getInts(IndexReader reader, String field)
          Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as integers and returns an array of size reader.maxDoc() of the value each document has in the given field.
 FieldCache.StringIndex getStringIndex(IndexReader reader, String field)
          Checks the internal cache for an appropriate entry, and if none is found reads the term values in field and returns an array of them in natural order, along with an array telling which element in the term array each document uses.
 String[] getStrings(IndexReader reader, String field)
          Checks the internal cache for an appropriate entry, and if none is found, reads the term values in field and returns an array of size reader.maxDoc() containing the value each document has in the given field.
(package private)  Object lookup(IndexReader reader, String field, int type)
          See if an object is in the cache.
(package private)  Object lookup(IndexReader reader, String field, Object comparer)
          See if a custom object is in the cache.
(package private)  Object store(IndexReader reader, String field, int type, Object value)
          Put an object into the cache.
(package private)  Object store(IndexReader reader, String field, Object comparer, Object value)
          Put a custom object into the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

final Map cache
The internal cache. Maps Entry to array of interpreted term values.

Constructor Detail

FieldCacheImpl

FieldCacheImpl()
Method Detail

lookup

Object lookup(IndexReader reader,
              String field,
              int type)
See if an object is in the cache.


lookup

Object lookup(IndexReader reader,
              String field,
              Object comparer)
See if a custom object is in the cache.


store

Object store(IndexReader reader,
             String field,
             int type,
             Object value)
Put an object into the cache.


store

Object store(IndexReader reader,
             String field,
             Object comparer,
             Object value)
Put a custom object into the cache.


getInts

public int[] getInts(IndexReader reader,
                     String field)
              throws IOException
Description copied from interface: FieldCache
Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as integers and returns an array of size reader.maxDoc() of the value each document has in the given field.

Specified by:
getInts in interface FieldCache
Parameters:
reader - Used to get field values.
field - Which field contains the integers.
Returns:
The values in the given field for each document.
Throws:
IOException - If any error occurs.

getFloats

public float[] getFloats(IndexReader reader,
                         String field)
                  throws IOException
Description copied from interface: FieldCache
Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as floats and returns an array of size reader.maxDoc() of the value each document has in the given field.

Specified by:
getFloats in interface FieldCache
Parameters:
reader - Used to get field values.
field - Which field contains the floats.
Returns:
The values in the given field for each document.
Throws:
IOException - If any error occurs.

getStrings

public String[] getStrings(IndexReader reader,
                           String field)
                    throws IOException
Description copied from interface: FieldCache
Checks the internal cache for an appropriate entry, and if none is found, reads the term values in field and returns an array of size reader.maxDoc() containing the value each document has in the given field.

Specified by:
getStrings in interface FieldCache
Parameters:
reader - Used to get field values.
field - Which field contains the strings.
Returns:
The values in the given field for each document.
Throws:
IOException - If any error occurs.

getStringIndex

public FieldCache.StringIndex getStringIndex(IndexReader reader,
                                             String field)
                                      throws IOException
Description copied from interface: FieldCache
Checks the internal cache for an appropriate entry, and if none is found reads the term values in field and returns an array of them in natural order, along with an array telling which element in the term array each document uses.

Specified by:
getStringIndex in interface FieldCache
Parameters:
reader - Used to get field values.
field - Which field contains the strings.
Returns:
Array of terms and index into the array for each document.
Throws:
IOException - If any error occurs.

getAuto

public Object getAuto(IndexReader reader,
                      String field)
               throws IOException
removed for java 1.3 compatibility protected static final Object pFloats = Pattern.compile ("[0-9+\\-\\.eEfFdD]+");

Specified by:
getAuto in interface FieldCache
Parameters:
reader - Used to get field values.
field - Which field contains the values.
Returns:
int[], float[] or StringIndex.
Throws:
IOException - If any error occurs.

getCustom

public Comparable[] getCustom(IndexReader reader,
                              String field,
                              SortComparator comparator)
                       throws IOException
Description copied from interface: FieldCache
Checks the internal cache for an appropriate entry, and if none is found reads the terms out of field and calls the given SortComparator to get the sort values. A hit in the cache will happen if reader, field, and comparator are the same (using equals()) as a previous call to this method.

Specified by:
getCustom in interface FieldCache
Parameters:
reader - Used to get field values.
field - Which field contains the values.
comparator - Used to convert terms into something to sort by.
Returns:
Array of sort objects, one for each document.
Throws:
IOException - If any error occurs.