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:
    FieldCacheSanityChecker
    • Method Detail

      • getDocsWithField

        Bits getDocsWithField​(IndexReader reader,
                              String field)
                       throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field and returns a bit set at the size of reader.maxDoc(), with turned on bits for each docid that does have a value for this field.
        Throws:
        IOException
      • getBytes

        byte[] getBytes​(IndexReader reader,
                        String field)
                 throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as a single byte and returns an array of size reader.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.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getBytes

        byte[] getBytes​(IndexReader reader,
                        String field,
                        FieldCache.ByteParser parser)
                 throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as bytes and returns an array of size reader.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.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getBytes

        byte[] getBytes​(IndexReader reader,
                        String field,
                        FieldCache.ByteParser parser,
                        boolean setDocsWithField)
                 throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as bytes and returns an array of size reader.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 then getDocsWithField(org.apache.lucene.index.IndexReader, 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

        short[] getShorts​(IndexReader reader,
                          String field)
                   throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as shorts and returns an array of size reader.maxDoc() of the value each document has in the given field.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the shorts.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getShorts

        short[] getShorts​(IndexReader reader,
                          String field,
                          FieldCache.ShortParser parser)
                   throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as shorts and returns an array of size reader.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.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getShorts

        short[] getShorts​(IndexReader reader,
                          String field,
                          FieldCache.ShortParser parser,
                          boolean setDocsWithField)
                   throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as shorts and returns an array of size reader.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 then getDocsWithField(org.apache.lucene.index.IndexReader, 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

        int[] getInts​(IndexReader reader,
                      String field)
               throws IOException
        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.
        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.
      • getInts

        int[] getInts​(IndexReader reader,
                      String field,
                      FieldCache.IntParser parser)
               throws IOException
        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.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the integers.
        parser - Computes integer for string values.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getInts

        int[] getInts​(IndexReader reader,
                      String field,
                      FieldCache.IntParser parser,
                      boolean setDocsWithField)
               throws IOException
        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.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the integers.
        parser - Computes integer for string values.
        setDocsWithField - If true then getDocsWithField(org.apache.lucene.index.IndexReader, 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

        float[] getFloats​(IndexReader reader,
                          String field)
                   throws IOException
        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.
        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.
      • getFloats

        float[] getFloats​(IndexReader reader,
                          String field,
                          FieldCache.FloatParser parser)
                   throws IOException
        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.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the floats.
        parser - Computes float for string values.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getFloats

        float[] getFloats​(IndexReader reader,
                          String field,
                          FieldCache.FloatParser parser,
                          boolean setDocsWithField)
                   throws IOException
        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.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the floats.
        parser - Computes float for string values.
        setDocsWithField - If true then getDocsWithField(org.apache.lucene.index.IndexReader, 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

        long[] getLongs​(IndexReader reader,
                        String field)
                 throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as longs and returns an array of size reader.maxDoc() of the value each document has in the given field.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the longs.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getLongs

        long[] getLongs​(IndexReader reader,
                        String field,
                        FieldCache.LongParser parser)
                 throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as longs and returns an array of size reader.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 integer for string values.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getLongs

        long[] getLongs​(IndexReader reader,
                        String field,
                        FieldCache.LongParser parser,
                        boolean setDocsWithField)
                 throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as longs and returns an array of size reader.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 integer for string values.
        setDocsWithField - If true then getDocsWithField(org.apache.lucene.index.IndexReader, 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

        double[] getDoubles​(IndexReader reader,
                            String field)
                     throws IOException
        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.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the doubles.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getDoubles

        double[] getDoubles​(IndexReader reader,
                            String field,
                            FieldCache.DoubleParser parser)
                     throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as doubles and returns an array of size reader.maxDoc() of the value each document has in the given field.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the doubles.
        parser - Computes integer for string values.
        Returns:
        The values in the given field for each document.
        Throws:
        IOException - If any error occurs.
      • getDoubles

        double[] getDoubles​(IndexReader reader,
                            String field,
                            FieldCache.DoubleParser parser,
                            boolean setDocsWithField)
                     throws IOException
        Checks the internal cache for an appropriate entry, and if none is found, reads the terms in field as doubles and returns an array of size reader.maxDoc() of the value each document has in the given field.
        Parameters:
        reader - Used to get field values.
        field - Which field contains the doubles.
        parser - Computes integer for string values.
        setDocsWithField - If true then getDocsWithField(org.apache.lucene.index.IndexReader, 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.
      • getStrings

        String[] getStrings​(IndexReader reader,
                            String field)
                     throws IOException
        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.
        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

        FieldCache.StringIndex getStringIndex​(IndexReader reader,
                                              String field)
                                       throws IOException
        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.
        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.
      • 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 IndexReader associated with it has garbage collected will prevent the Value itself from being garbage collected when the Cache drops the WeakReference.

        WARNING: This API is experimental and might change in incompatible ways in the next release.
      • 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.

        WARNING: This API is experimental and might change in incompatible ways in the next release.
      • purge

        void purge​(IndexReader r)
        Expert: drops all cache entries associated with this reader. NOTE: this reader 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

        void setInfoStream​(PrintStream stream)
        If non-null, FieldCacheImpl will warn whenever entries are created that are not sane according to FieldCacheSanityChecker.