Package org.apache.lucene.search
Interface FieldCache
public interface FieldCache
Expert: Maintains caches of term values.
Created: May 19, 2004 11:13:14 AM
- Since:
- lucene 1.4
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Deprecated.static class
Field values as 8-bit signed bytesstatic final class
EXPERT: A unique Identifier/Description for each item in the FieldCache.static final class
Placeholder indicating creation of this cache is currently in-progress.static interface
Interface to parse doubles from document fields.static class
Field values as 64-bit doublesstatic interface
Interface to parse floats from document fields.static class
Field values as 32-bit floatsstatic interface
Interface to parse ints from document fields.static class
Field values as 32-bit signed integersstatic interface
Interface to parse long from document fields.static class
Field values as 64-bit signed long integersstatic interface
Marker interface as super-interface to all parsers.static interface
Deprecated.static class
Field values as 16-bit signed shorts -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FieldCache
Expert: The cache used internally by sorting and range query classes.static final FieldCache.ByteParser
Deprecated.static final FieldCache.DoubleParser
Deprecated.static final FieldCache.FloatParser
Deprecated.static final FieldCache.IntParser
Deprecated.static final FieldCache.LongParser
Deprecated.static final FieldCache.ShortParser
Deprecated.static final FieldCache.DoubleParser
A parser instance for double values encoded withNumericUtils
, e.g.static final FieldCache.FloatParser
A parser instance for float values encoded withNumericUtils
, e.g.static final FieldCache.IntParser
A parser instance for int values encoded byNumericUtils
, e.g.static final FieldCache.LongParser
A parser instance for long values encoded byNumericUtils
, e.g. -
Method Summary
Modifier and TypeMethodDescriptiongetBytes
(AtomicReader reader, String field, boolean setDocsWithField) Deprecated.getBytes
(AtomicReader reader, String field, FieldCache.ByteParser parser, boolean setDocsWithField) Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.EXPERT: Generates an array of CacheEntry objects representing all items currently in the FieldCache.getDocsWithField
(AtomicReader reader, String field) Checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
and returns a bit set at the size ofreader.maxDoc()
, with turned on bits for each docid that does have a value for this field.getDocTermOrds
(AtomicReader reader, String field) Checks the internal cache for an appropriate entry, and if none is found, reads the term values infield
and returns aDocTermOrds
instance, providing a method to retrieve the terms (as ords) per document.getDoubles
(AtomicReader reader, String field, boolean setDocsWithField) Returns aFieldCache.Doubles
over the values found in documents in the given field.getDoubles
(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField) Returns aFieldCache.Doubles
over the values found in documents in the given field.getFloats
(AtomicReader reader, String field, boolean setDocsWithField) Returns aFieldCache.Floats
over the values found in documents in the given field.getFloats
(AtomicReader reader, String field, FieldCache.FloatParser parser, boolean setDocsWithField) Returns aFieldCache.Floats
over the values found in documents in the given field.counterpart ofsetInfoStream(PrintStream)
getInts
(AtomicReader reader, String field, boolean setDocsWithField) Returns anFieldCache.Ints
over the values found in documents in the given field.getInts
(AtomicReader reader, String field, FieldCache.IntParser parser, boolean setDocsWithField) Returns anFieldCache.Ints
over the values found in documents in the given field.getLongs
(AtomicReader reader, String field, boolean setDocsWithField) Returns aFieldCache.Longs
over the values found in documents in the given field.getLongs
(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField) Returns aFieldCache.Longs
over the values found in documents in the given field.getShorts
(AtomicReader reader, String field, boolean setDocsWithField) Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.getShorts
(AtomicReader reader, String field, FieldCache.ShortParser parser, boolean setDocsWithField) Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.getTerms
(AtomicReader reader, String field, boolean setDocsWithField) Checks the internal cache for an appropriate entry, and if none is found, reads the term values infield
and returns aBinaryDocValues
instance, providing a method to retrieve the term (as a BytesRef) per document.getTerms
(AtomicReader reader, String field, boolean setDocsWithField, float acceptableOverheadRatio) Expert: just likegetTerms(AtomicReader,String,boolean)
, but you can specify whether more RAM should be consumed in exchange for faster lookups (default is "true").getTermsIndex
(AtomicReader reader, String field) Checks the internal cache for an appropriate entry, and if none is found, reads the term values infield
and returns aSortedDocValues
instance, providing methods to retrieve sort ordinals and terms (as a ByteRef) per document.getTermsIndex
(AtomicReader reader, String field, float acceptableOverheadRatio) Expert: just likegetTermsIndex(AtomicReader,String)
, but you can specify whether more RAM should be consumed in exchange for faster lookups (default is "true").void
EXPERT: Instructs the FieldCache to forcibly expunge all entries from the underlying caches.void
purgeByCacheKey
(Object coreCacheKey) Expert: drops all cache entries associated with this readerIndexReader.getCoreCacheKey()
.void
setInfoStream
(PrintStream stream) If non-null, FieldCacheImpl will warn whenever entries are created that are not sane according toFieldCacheSanityChecker
.
-
Field Details
-
DEFAULT
Expert: The cache used internally by sorting and range query classes. -
DEFAULT_BYTE_PARSER
Deprecated.The default parser for byte values, which are encoded byByte.toString(byte)
-
DEFAULT_SHORT_PARSER
Deprecated.The default parser for short values, which are encoded byShort.toString(short)
-
DEFAULT_INT_PARSER
Deprecated.The default parser for int values, which are encoded byInteger.toString(int)
-
DEFAULT_FLOAT_PARSER
Deprecated.The default parser for float values, which are encoded byFloat.toString(float)
-
DEFAULT_LONG_PARSER
Deprecated.The default parser for long values, which are encoded byLong.toString(long)
-
DEFAULT_DOUBLE_PARSER
Deprecated.The default parser for double values, which are encoded byDouble.toString(double)
-
NUMERIC_UTILS_INT_PARSER
A parser instance for int values encoded byNumericUtils
, e.g. when indexed viaIntField
/NumericTokenStream
. -
NUMERIC_UTILS_FLOAT_PARSER
A parser instance for float values encoded withNumericUtils
, e.g. when indexed viaFloatField
/NumericTokenStream
. -
NUMERIC_UTILS_LONG_PARSER
A parser instance for long values encoded byNumericUtils
, e.g. when indexed viaLongField
/NumericTokenStream
. -
NUMERIC_UTILS_DOUBLE_PARSER
A parser instance for double values encoded withNumericUtils
, e.g. when indexed viaDoubleField
/NumericTokenStream
.
-
-
Method Details
-
getDocsWithField
Checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
and returns a bit set at the size ofreader.maxDoc()
, with turned on bits for each docid that does have a value for this field.- Throws:
IOException
-
getBytes
@Deprecated FieldCache.Bytes getBytes(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.Checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as a single byte and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the single byte values.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getBytes
@Deprecated FieldCache.Bytes getBytes(AtomicReader reader, String field, FieldCache.ByteParser parser, boolean setDocsWithField) throws IOException Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.Checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as bytes and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the bytes.parser
- Computes byte for string values.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getShorts
@Deprecated FieldCache.Shorts getShorts(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.Checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as shorts and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the shorts.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getShorts
@Deprecated FieldCache.Shorts getShorts(AtomicReader reader, String field, FieldCache.ShortParser parser, boolean setDocsWithField) throws IOException Deprecated.(4.4) Index as a numeric field usingIntField
and then usegetInts(AtomicReader, String, boolean)
instead.Checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as shorts and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the shorts.parser
- Computes short for string values.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getInts
FieldCache.Ints getInts(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Returns anFieldCache.Ints
over the values found in documents in the given field.- Throws:
IOException
- See Also:
-
getInts
FieldCache.Ints getInts(AtomicReader reader, String field, FieldCache.IntParser parser, boolean setDocsWithField) throws IOException Returns anFieldCache.Ints
over the values found in documents in the given field. If the field was indexed asNumericDocValuesField
, it simply usesAtomicReader.getNumericDocValues(String)
to read the values. Otherwise, it checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as ints and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the longs.parser
- Computes int for string values. May benull
if the requested field was indexed asNumericDocValuesField
orIntField
.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getFloats
FieldCache.Floats getFloats(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Returns aFieldCache.Floats
over the values found in documents in the given field.- Throws:
IOException
- See Also:
-
getFloats
FieldCache.Floats getFloats(AtomicReader reader, String field, FieldCache.FloatParser parser, boolean setDocsWithField) throws IOException Returns aFieldCache.Floats
over the values found in documents in the given field. If the field was indexed asNumericDocValuesField
, it simply usesAtomicReader.getNumericDocValues(String)
to read the values. Otherwise, it checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as floats and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the floats.parser
- Computes float for string values. May benull
if the requested field was indexed asNumericDocValuesField
orFloatField
.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getLongs
FieldCache.Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Returns aFieldCache.Longs
over the values found in documents in the given field.- Throws:
IOException
- See Also:
-
getLongs
FieldCache.Longs getLongs(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField) throws IOException Returns aFieldCache.Longs
over the values found in documents in the given field. If the field was indexed asNumericDocValuesField
, it simply usesAtomicReader.getNumericDocValues(String)
to read the values. Otherwise, it checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as longs and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the longs.parser
- Computes long for string values. May benull
if the requested field was indexed asNumericDocValuesField
orLongField
.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getDoubles
FieldCache.Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Returns aFieldCache.Doubles
over the values found in documents in the given field.- Throws:
IOException
- See Also:
-
getDoubles
FieldCache.Doubles getDoubles(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField) throws IOException Returns aFieldCache.Doubles
over the values found in documents in the given field. If the field was indexed asNumericDocValuesField
, it simply usesAtomicReader.getNumericDocValues(String)
to read the values. Otherwise, it checks the internal cache for an appropriate entry, and if none is found, reads the terms infield
as doubles and returns an array of sizereader.maxDoc()
of the value each document has in the given field.- Parameters:
reader
- Used to get field values.field
- Which field contains the longs.parser
- Computes double for string values. May benull
if the requested field was indexed asNumericDocValuesField
orDoubleField
.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getTerms
BinaryDocValues getTerms(AtomicReader reader, String field, boolean setDocsWithField) throws IOException Checks the internal cache for an appropriate entry, and if none is found, reads the term values infield
and returns aBinaryDocValues
instance, providing a method to retrieve the term (as a BytesRef) per document.- Parameters:
reader
- Used to get field values.field
- Which field contains the strings.setDocsWithField
- If true thengetDocsWithField(org.apache.lucene.index.AtomicReader, java.lang.String)
will also be computed and stored in the FieldCache.- Returns:
- The values in the given field for each document.
- Throws:
IOException
- If any error occurs.
-
getTerms
BinaryDocValues getTerms(AtomicReader reader, String field, boolean setDocsWithField, float acceptableOverheadRatio) throws IOException Expert: just likegetTerms(AtomicReader,String,boolean)
, but you can specify whether more RAM should be consumed in exchange for faster lookups (default is "true"). Note that the first call for a given reader and field "wins", subsequent calls will share the same cache entry.- Throws:
IOException
-
getTermsIndex
Checks the internal cache for an appropriate entry, and if none is found, reads the term values infield
and returns aSortedDocValues
instance, providing methods to retrieve sort ordinals and terms (as a ByteRef) per document.- 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.
-
getTermsIndex
SortedDocValues getTermsIndex(AtomicReader reader, String field, float acceptableOverheadRatio) throws IOException Expert: just likegetTermsIndex(AtomicReader,String)
, but you can specify whether more RAM should be consumed in exchange for faster lookups (default is "true"). Note that the first call for a given reader and field "wins", subsequent calls will share the same cache entry.- Throws:
IOException
-
getDocTermOrds
Checks the internal cache for an appropriate entry, and if none is found, reads the term values infield
and returns aDocTermOrds
instance, providing a method to retrieve the terms (as ords) per document.- Parameters:
reader
- Used to build aDocTermOrds
instancefield
- Which field contains the strings.- Returns:
- a
DocTermOrds
instance - Throws:
IOException
- If any error occurs.
-
getCacheEntries
FieldCache.CacheEntry[] getCacheEntries()EXPERT: Generates an array of CacheEntry objects representing all items currently in the FieldCache.NOTE: These CacheEntry objects maintain a strong reference to the Cached Values. Maintaining references to a CacheEntry the AtomicIndexReader associated with it has garbage collected will prevent the Value itself from being garbage collected when the Cache drops the WeakReference.
-
purgeAllCaches
void purgeAllCaches()EXPERT: Instructs the FieldCache to forcibly expunge all entries from the underlying caches. This is intended only to be used for test methods as a way to ensure a known base state of the Cache (with out needing to rely on GC to free WeakReferences). It should not be relied on for "Cache maintenance" in general application code.
-
purgeByCacheKey
Expert: drops all cache entries associated with this readerIndexReader.getCoreCacheKey()
. NOTE: this cache key must precisely match the reader that the cache entry is keyed on. If you pass a top-level reader, it usually will have no effect as Lucene now caches at the segment reader level. -
setInfoStream
If non-null, FieldCacheImpl will warn whenever entries are created that are not sane according toFieldCacheSanityChecker
. -
getInfoStream
PrintStream getInfoStream()counterpart ofsetInfoStream(PrintStream)
-
IntField
and then usegetInts(AtomicReader, String, boolean)
instead.