## org.apache.lucene.search.function
Class FieldCacheSource

    java.lang.Object
      org.apache.lucene.search.function.ValueSource
          org.apache.lucene.search.function.FieldCacheSource

All Implemented Interfaces:
  java.io.Serializable

Direct Known Subclasses:
  ByteFieldSource, FloatFieldSource, IntFieldSource, ShortFieldSource

    public abstract class FieldCacheSource

extends ValueSource

Expert: A base class for ValueSource implementations that retrieve values for a single field from the `FieldCache`.

Fields used herein must be indexed (doesn't matter if these fields are stored or not).

It is assumed that each such indexed field is untokenized, or at least has a single token in a document. For documents with multiple tokens of the same field, behavior is undefined (It is likely that current code would use the value of one of these tokens, but this is not guaranteed).

Document with no tokens in this field are assigned the `Zero` value.

WARNING: The status of the search.function package is experimental. The APIs introduced here might change in the future and will not be supported anymore in such a case.

NOTE: with the switch in 2.9 to segment-based searching, if `getValues(org.apache.lucene.index.IndexReader)` is invoked with a composite (multi-segment) reader, this can easily cause double RAM usage for the values in the FieldCache. It's best to switch your application to pass only atomic (single segment) readers to this API. Alternatively, for a short-term fix, you could wrap your ValueSource using `MultiValueSource`, which costs more CPU per lookup but will not consume double the FieldCache RAM.

See Also:
  Serialized Form

Constructor Summary
`FieldCacheSource(java.lang.String field)` Create a cached field source for the input field.

Method Summary
`abstract boolean` `cachedFieldSourceEquals(FieldCacheSource other)` Check if equals to another `FieldCacheSource`, already knowing that cache and field are equal.
`abstract int` `cachedFieldSourceHashCode()` Return a hash code of a `FieldCacheSource`, without the hash-codes of the field and the cache (those are taken care of elsewhere).
`java.lang.String` `description()` description of field, used in explain()
`boolean` `equals(java.lang.Object o)` Needed for possible caching of query results - used by `ValueSourceQuery.equals(Object)`.
`abstract DocValues` `getCachedFieldValues(FieldCache cache, java.lang.String field, IndexReader reader)` Return cached DocValues for input field and reader.
`DocValues` `getValues(IndexReader reader)` Return the DocValues used by the function query.
`int` `hashCode()` Needed for possible caching of query results - used by `ValueSourceQuery.hashCode()`.

Methods inherited from class org.apache.lucene.search.function.ValueSource
`toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Constructor Detail

### FieldCacheSource

    public FieldCacheSource(java.lang.String field)

  Create a cached field source for the input field.

Method Detail

### getValues

    public final DocValues getValues(IndexReader reader)
                              throws java.io.IOException

  Description copied from class: `ValueSource`
  Return the DocValues used by the function query.

  Specified by:
    `getValues` in class `ValueSource`
  Parameters:
    `reader` - the IndexReader used to read these values. If any caching is involved, that caching would also be IndexReader based.
  Throws:
    `java.io.IOException` - for any error.

### description

    public java.lang.String description()

  Description copied from class: `ValueSource`
  description of field, used in explain()

  Specified by:
    `description` in class `ValueSource`

### getCachedFieldValues

    public abstract DocValues getCachedFieldValues(FieldCache cache,
                                                   java.lang.String field,
                                                   IndexReader reader)
                                            throws java.io.IOException

  Return cached DocValues for input field and reader.

  Parameters:
    `cache` - FieldCache so that values of a field are loaded once per reader (RAM allowing)
    `field` - Field for which values are required.
  Throws:
    `java.io.IOException`
  See Also:
    `ValueSource`

### equals

    public final boolean equals(java.lang.Object o)

  Description copied from class: `ValueSource`
  Needed for possible caching of query results - used by `ValueSourceQuery.equals(Object)`.

  Specified by:
    `equals` in class `ValueSource`
  See Also:
    `Object.equals(Object)`

### hashCode

    public final int hashCode()

  Description copied from class: `ValueSource`
  Needed for possible caching of query results - used by `ValueSourceQuery.hashCode()`.

  Specified by:
    `hashCode` in class `ValueSource`
  See Also:
    `Object.hashCode()`

### cachedFieldSourceEquals

    public abstract boolean cachedFieldSourceEquals(FieldCacheSource other)

  Check if equals to another `FieldCacheSource`, already knowing that cache and field are equal.

  See Also:
    `Object.equals(java.lang.Object)`

### cachedFieldSourceHashCode

    public abstract int cachedFieldSourceHashCode()

  Return a hash code of a `FieldCacheSource`, without the hash-codes of the field and the cache (those are taken care of elsewhere).

  See Also:
    `Object.hashCode()`

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.