Apache Lucene open-source search software
LUCENE-5234: improve FieldCache API
Shai Ereraadba0da04598
diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldCache.java b/lucene/core/src/java/org/apache/lucene/search/FieldCache.javaindex f08621f8206..7c0e54946ce 100644--- a/lucene/core/src/java/org/apache/lucene/search/FieldCache.java+++ b/lucene/core/src/java/org/apache/lucene/search/FieldCache.java@@ -20,11 +20,12 @@ package org.apache.lucene.search;import java.io.IOException;import java.io.PrintStream;-import org.apache.lucene.analysis.NumericTokenStream; // for javadocs-import org.apache.lucene.document.DoubleField; // for javadocs-import org.apache.lucene.document.FloatField; // for javadocs-import org.apache.lucene.document.IntField; // for javadocs-import org.apache.lucene.document.LongField; // for javadocs+import org.apache.lucene.analysis.NumericTokenStream;+import org.apache.lucene.document.DoubleField;+import org.apache.lucene.document.FloatField;+import org.apache.lucene.document.IntField;+import org.apache.lucene.document.LongField;+import org.apache.lucene.document.NumericDocValuesField;import org.apache.lucene.index.AtomicReader;import org.apache.lucene.index.BinaryDocValues;import org.apache.lucene.index.DocTermOrds;@@ -253,122 +254,139 @@ public interface FieldCache {*/public Bits getDocsWithField(AtomicReader reader, String field) throws IOException;- /** Checks the internal cache for an appropriate entry, and if none is- * found, reads the terms in <code>field</code> as integers and returns an array- * of size <code>reader.maxDoc()</code> of the value each document- * has in the given field.- * @param reader Used to get field values.- * @param field Which field contains the integers.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.- * @return The values in the given field for each document.- * @throws IOException If any error occurs.+ /**+ * Returns an {@link Ints} over the values found in documents in the given+ * field.+ *+ * @see #getInts(AtomicReader, String, IntParser, boolean)*/public Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException;- /** Checks the internal cache for an appropriate entry, and if none is found,- * reads the terms in <code>field</code> as integers and returns an array of- * size <code>reader.maxDoc()</code> of the value each document has in the- * given field.- * @param reader Used to get field values.- * @param field Which field contains the integers.- * @param parser Computes integer for string values.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.+ /**+ * Returns an {@link Ints} over the values found in documents in the given+ * field. If the field was indexed as {@link NumericDocValuesField}, it simply+ * uses {@link AtomicReader#getNumericDocValues(String)} to read the values.+ * Otherwise, it checks the internal cache for an appropriate entry, and if+ * none is found, reads the terms in <code>field</code> as ints and returns+ * an array of size <code>reader.maxDoc()</code> of the value each document+ * has in the given field.+ *+ * @param reader+ * Used to get field values.+ * @param field+ * Which field contains the longs.+ * @param parser+ * Computes int for string values. May be {@code null} if the+ * requested field was indexed as {@link NumericDocValuesField} or+ * {@link IntField}.+ * @param setDocsWithField+ * If true then {@link #getDocsWithField} will also be computed and+ * stored in the FieldCache.* @return The values in the given field for each document.- * @throws IOException If any error occurs.+ * @throws IOException+ * If any error occurs.*/public Ints getInts (AtomicReader reader, String field, IntParser parser, boolean setDocsWithField) throws IOException;- /** Checks the internal cache for an appropriate entry, and if- * none is found, reads the terms in <code>field</code> as floats and returns an array- * of size <code>reader.maxDoc()</code> of the value each document- * has in the given field.- * @param reader Used to get field values.- * @param field Which field contains the floats.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.- * @return The values in the given field for each document.- * @throws IOException If any error occurs.+ /**+ * Returns a {@link Floats} over the values found in documents in the given+ * field.+ *+ * @see #getFloats(AtomicReader, String, FloatParser, boolean)*/public Floats getFloats (AtomicReader reader, String field, boolean setDocsWithField) throws IOException;- /** Checks the internal cache for an appropriate entry, and if- * none is found, reads the terms in <code>field</code> as floats and returns an array- * of size <code>reader.maxDoc()</code> of the value each document+ /**+ * Returns a {@link Floats} over the values found in documents in the given+ * field. If the field was indexed as {@link NumericDocValuesField}, it simply+ * uses {@link AtomicReader#getNumericDocValues(String)} to read the values.+ * Otherwise, it checks the internal cache for an appropriate entry, and if+ * none is found, reads the terms in <code>field</code> as floats and returns+ * an array of size <code>reader.maxDoc()</code> of the value each document* has in the given field.- * @param reader Used to get field values.- * @param field Which field contains the floats.- * @param parser Computes float for string values.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.+ *+ * @param reader+ * Used to get field values.+ * @param field+ * Which field contains the floats.+ * @param parser+ * Computes float for string values. May be {@code null} if the+ * requested field was indexed as {@link NumericDocValuesField} or+ * {@link FloatField}.+ * @param setDocsWithField+ * If true then {@link #getDocsWithField} will also be computed and+ * stored in the FieldCache.* @return The values in the given field for each document.- * @throws IOException If any error occurs.+ * @throws IOException+ * If any error occurs.*/public Floats getFloats (AtomicReader reader, String field, FloatParser parser, boolean setDocsWithField) throws IOException;/**- * Checks the internal cache for an appropriate entry, and if none is- * found, reads the terms in <code>field</code> as longs and returns an array- * of size <code>reader.maxDoc()</code> of the value each document- * has in the given field.+ * Returns a {@link Longs} over the values found in documents in the given+ * field.*- * @param reader Used to get field values.- * @param field Which field contains the longs.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.- * @return The values in the given field for each document.- * @throws java.io.IOException If any error occurs.+ * @see #getLongs(AtomicReader, String, LongParser, boolean)*/- public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField)- throws IOException;+ public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException;/**- * Checks the internal cache for an appropriate entry, and if none is found,- * reads the terms in <code>field</code> as longs and returns an array of- * size <code>reader.maxDoc()</code> of the value each document has in the- * given field.- *- * @param reader Used to get field values.- * @param field Which field contains the longs.- * @param parser Computes integer for string values.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.+ * Returns a {@link Longs} over the values found in documents in the given+ * field. If the field was indexed as {@link NumericDocValuesField}, it simply+ * uses {@link AtomicReader#getNumericDocValues(String)} to read the values.+ * Otherwise, it checks the internal cache for an appropriate entry, and if+ * none is found, reads the terms in <code>field</code> as longs and returns+ * an array of size <code>reader.maxDoc()</code> of the value each document+ * has in the given field.+ *+ * @param reader+ * Used to get field values.+ * @param field+ * Which field contains the longs.+ * @param parser+ * Computes long for string values. May be {@code null} if the+ * requested field was indexed as {@link NumericDocValuesField} or+ * {@link LongField}.+ * @param setDocsWithField+ * If true then {@link #getDocsWithField} will also be computed and+ * stored in the FieldCache.* @return The values in the given field for each document.- * @throws IOException If any error occurs.+ * @throws IOException+ * If any error occurs.*/- public Longs getLongs(AtomicReader reader, String field, LongParser parser, boolean setDocsWithField)- throws IOException;+ public Longs getLongs(AtomicReader reader, String field, LongParser parser, boolean setDocsWithField) throws IOException;/**- * Checks the internal cache for an appropriate entry, and if none is- * found, reads the terms in <code>field</code> as integers and returns an array- * of size <code>reader.maxDoc()</code> of the value each document- * has in the given field.+ * Returns a {@link Doubles} over the values found in documents in the given+ * field.*- * @param reader Used to get field values.- * @param field Which field contains the doubles.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.- * @return The values in the given field for each document.- * @throws IOException If any error occurs.+ * @see #getDoubles(AtomicReader, String, DoubleParser, boolean)*/- public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField)- throws IOException;+ public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField) throws IOException;/**- * Checks the internal cache for an appropriate entry, and if none is found,- * reads the terms in <code>field</code> as doubles and returns an array of- * size <code>reader.maxDoc()</code> of the value each document has in the- * given field.- *- * @param reader Used to get field values.- * @param field Which field contains the doubles.- * @param parser Computes integer for string values.- * @param setDocsWithField If true then {@link #getDocsWithField} will- * also be computed and stored in the FieldCache.+ * Returns a {@link Doubles} over the values found in documents in the given+ * field. If the field was indexed as {@link NumericDocValuesField}, it simply+ * uses {@link AtomicReader#getNumericDocValues(String)} to read the values.+ * Otherwise, it checks the internal cache for an appropriate entry, and if+ * none is found, reads the terms in <code>field</code> as doubles and returns+ * an array of size <code>reader.maxDoc()</code> of the value each document+ * has in the given field.+ *+ * @param reader+ * Used to get field values.+ * @param field+ * Which field contains the longs.+ * @param parser+ * Computes double for string values. May be {@code null} if the+ * requested field was indexed as {@link NumericDocValuesField} or+ * {@link DoubleField}.+ * @param setDocsWithField+ * If true then {@link #getDocsWithField} will also be computed and+ * stored in the FieldCache.* @return The values in the given field for each document.- * @throws IOException If any error occurs.+ * @throws IOException+ * If any error occurs.*/public Doubles getDoubles(AtomicReader reader, String field, DoubleParser parser, boolean setDocsWithField) throws IOException;diff --git a/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java b/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.javaindex 85b77d902bc..6d2ff2b41b9 100644--- a/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java+++ b/lucene/core/src/java/org/apache/lucene/search/FieldCacheImpl.java@@ -353,12 +353,12 @@ class FieldCacheImpl implements FieldCache {caches.get(DocsWithFieldCache.class).put(reader, new CacheKey(field, null), bits);}- // inherit javadocs+ @Overridepublic Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException {return getInts(reader, field, null, setDocsWithField);}- // inherit javadocs+ @Overridepublic Ints getInts(AtomicReader reader, String field, IntParser parser, boolean setDocsWithField)throws IOException {final NumericDocValues valuesIn = reader.getNumericDocValues(field);@@ -565,13 +565,13 @@ class FieldCacheImpl implements FieldCache {}}- // inherit javadocs+ @Overridepublic Floats getFloats (AtomicReader reader, String field, boolean setDocsWithField)throws IOException {return getFloats(reader, field, null, setDocsWithField);}- // inherit javadocs+ @Overridepublic Floats getFloats(AtomicReader reader, String field, FloatParser parser, boolean setDocsWithField)throws IOException {final NumericDocValues valuesIn = reader.getNumericDocValues(field);@@ -671,12 +671,12 @@ class FieldCacheImpl implements FieldCache {}}- // inherit javadocs+ @Overridepublic Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException {return getLongs(reader, field, null, setDocsWithField);}- // inherit javadocs+ @Overridepublic Longs getLongs(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField)throws IOException {final NumericDocValues valuesIn = reader.getNumericDocValues(field);@@ -790,13 +790,13 @@ class FieldCacheImpl implements FieldCache {}}- // inherit javadocs+ @Overridepublic Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField)throws IOException {return getDoubles(reader, field, null, setDocsWithField);}- // inherit javadocs+ @Overridepublic Doubles getDoubles(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField)throws IOException {final NumericDocValues valuesIn = reader.getNumericDocValues(field);diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.javaindex 73c5d497548..d4951b5ba0f 100644--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/DoubleFieldSource.java@@ -31,13 +31,9 @@ import org.apache.lucene.util.mutable.MutableValue;import org.apache.lucene.util.mutable.MutableValueDouble;/**- * Obtains float field values from the {@link org.apache.lucene.search.FieldCache}- * using <code>getFloats()</code>- * and makes those values available as other numeric types, casting as needed.- *- *+ * Obtains double field values from {@link FieldCache#getDoubles} and makes+ * those values available as other numeric types, casting as needed.*/-public class DoubleFieldSource extends FieldCacheSource {protected final FieldCache.DoubleParser parser;diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.javaindex c81526365c4..3c7f3b1bb6a 100644--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/FloatFieldSource.java@@ -29,13 +29,9 @@ import org.apache.lucene.util.mutable.MutableValue;import org.apache.lucene.util.mutable.MutableValueFloat;/**- * Obtains float field values from the {@link org.apache.lucene.search.FieldCache}- * using <code>getFloats()</code>- * and makes those values available as other numeric types, casting as needed.- *- *+ * Obtains float field values from {@link FieldCache#getFloats} and makes those+ * values available as other numeric types, casting as needed.*/-public class FloatFieldSource extends FieldCacheSource {protected final FieldCache.FloatParser parser;diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.javaindex 768d9d77e5a..06f8552d681 100644--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/IntFieldSource.java@@ -31,12 +31,9 @@ import org.apache.lucene.util.mutable.MutableValue;import org.apache.lucene.util.mutable.MutableValueInt;/**- * Obtains int field values from the {@link org.apache.lucene.search.FieldCache}- * using <code>getInts()</code>- * and makes those values available as other numeric types, casting as needed. *- *+ * Obtains int field values from {@link FieldCache#getInts} and makes those+ * values available as other numeric types, casting as needed.*/-public class IntFieldSource extends FieldCacheSource {final FieldCache.IntParser parser;diff --git a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.javaindex d1718313d8b..90720b15fdf 100644--- a/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java+++ b/lucene/queries/src/java/org/apache/lucene/queries/function/valuesource/LongFieldSource.java@@ -31,13 +31,9 @@ import org.apache.lucene.util.mutable.MutableValue;import org.apache.lucene.util.mutable.MutableValueLong;/**- * Obtains float field values from the {@link org.apache.lucene.search.FieldCache}- * using <code>getFloats()</code>- * and makes those values available as other numeric types, casting as needed.- *- *+ * Obtains long field values from {@link FieldCache#getLongs} and makes those+ * values available as other numeric types, casting as needed.*/-public class LongFieldSource extends FieldCacheSource {protected final FieldCache.LongParser parser;