LUCENE-5234: improve FieldCache API

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1525284 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2013-09-21 19:30:17 +00:00
parent da34b18cb3
commit adba0da045
6 changed files with 128 additions and 125 deletions

View File

@ -20,11 +20,12 @@ package org.apache.lucene.search;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import org.apache.lucene.analysis.NumericTokenStream; // for javadocs import org.apache.lucene.analysis.NumericTokenStream;
import org.apache.lucene.document.DoubleField; // for javadocs import org.apache.lucene.document.DoubleField;
import org.apache.lucene.document.FloatField; // for javadocs import org.apache.lucene.document.FloatField;
import org.apache.lucene.document.IntField; // for javadocs import org.apache.lucene.document.IntField;
import org.apache.lucene.document.LongField; // for javadocs import org.apache.lucene.document.LongField;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.index.AtomicReader; import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.BinaryDocValues; import org.apache.lucene.index.BinaryDocValues;
import org.apache.lucene.index.DocTermOrds; import org.apache.lucene.index.DocTermOrds;
@ -253,122 +254,139 @@ public interface FieldCache {
*/ */
public Bits getDocsWithField(AtomicReader reader, String field) throws IOException; 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 * Returns an {@link Ints} over the values found in documents in the given
* of size <code>reader.maxDoc()</code> of the value each document * field.
* has in the given field. *
* @param reader Used to get field values. * @see #getInts(AtomicReader, String, IntParser, boolean)
* @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.
*/ */
public Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException; 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 * Returns an {@link Ints} over the values found in documents in the given
* size <code>reader.maxDoc()</code> of the value each document has in the * field. If the field was indexed as {@link NumericDocValuesField}, it simply
* given field. * uses {@link AtomicReader#getNumericDocValues(String)} to read the values.
* @param reader Used to get field values. * Otherwise, it checks the internal cache for an appropriate entry, and if
* @param field Which field contains the integers. * none is found, reads the terms in <code>field</code> as ints and returns
* @param parser Computes integer for string values. * an array of size <code>reader.maxDoc()</code> of the value each document
* @param setDocsWithField If true then {@link #getDocsWithField} will * has in the given field.
* also be computed and stored in the FieldCache. *
* @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. * @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; 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 * Returns a {@link Floats} over the values found in documents in the given
* of size <code>reader.maxDoc()</code> of the value each document * field.
* has in the given field. *
* @param reader Used to get field values. * @see #getFloats(AtomicReader, String, FloatParser, boolean)
* @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.
*/ */
public Floats getFloats (AtomicReader reader, String field, boolean setDocsWithField) throws IOException; 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 * Returns a {@link Floats} over the values found in documents in the given
* of size <code>reader.maxDoc()</code> of the value each document * 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. * has in the given field.
* @param reader Used to get field values. *
* @param field Which field contains the floats. * @param reader
* @param parser Computes float for string values. * Used to get field values.
* @param setDocsWithField If true then {@link #getDocsWithField} will * @param field
* also be computed and stored in the FieldCache. * 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. * @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; 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 * Returns a {@link Longs} over the values found in documents in the given
* found, reads the terms in <code>field</code> as longs and returns an array * field.
* of size <code>reader.maxDoc()</code> of the value each document *
* @see #getLongs(AtomicReader, String, LongParser, boolean)
*/
public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException;
/**
* 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. * has in the given field.
* *
* @param reader Used to get field values. * @param reader
* @param field Which field contains the longs. * Used to get field values.
* @param setDocsWithField If true then {@link #getDocsWithField} will * @param field
* also be computed and stored in the FieldCache. * 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. * @return The values in the given field for each document.
* @throws java.io.IOException If any error occurs. * @throws IOException
* If any error occurs.
*/ */
public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) public Longs getLongs(AtomicReader reader, String field, LongParser parser, boolean setDocsWithField) throws IOException;
throws IOException;
/** /**
* Checks the internal cache for an appropriate entry, and if none is found, * Returns a {@link Doubles} over the values found in documents in the given
* reads the terms in <code>field</code> as longs and returns an array of * field.
* size <code>reader.maxDoc()</code> of the value each document has in the
* given field.
* *
* @param reader Used to get field values. * @see #getDoubles(AtomicReader, String, DoubleParser, boolean)
* @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.
* @return The values in the given field for each document.
* @throws IOException If any error occurs.
*/ */
public Longs getLongs(AtomicReader reader, String field, LongParser parser, boolean setDocsWithField) public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField) throws IOException;
throws IOException;
/** /**
* Checks the internal cache for an appropriate entry, and if none is * Returns a {@link Doubles} over the values found in documents in the given
* found, reads the terms in <code>field</code> as integers and returns an array * field. If the field was indexed as {@link NumericDocValuesField}, it simply
* of size <code>reader.maxDoc()</code> of the value each document * 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. * has in the given field.
* *
* @param reader Used to get field values. * @param reader
* @param field Which field contains the doubles. * Used to get field values.
* @param setDocsWithField If true then {@link #getDocsWithField} will * @param field
* also be computed and stored in the FieldCache. * 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. * @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, 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.
* @return The values in the given field for each document.
* @throws IOException If any error occurs.
*/ */
public Doubles getDoubles(AtomicReader reader, String field, DoubleParser parser, boolean setDocsWithField) throws IOException; public Doubles getDoubles(AtomicReader reader, String field, DoubleParser parser, boolean setDocsWithField) throws IOException;

View File

@ -353,12 +353,12 @@ class FieldCacheImpl implements FieldCache {
caches.get(DocsWithFieldCache.class).put(reader, new CacheKey(field, null), bits); caches.get(DocsWithFieldCache.class).put(reader, new CacheKey(field, null), bits);
} }
// inherit javadocs @Override
public Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException { public Ints getInts (AtomicReader reader, String field, boolean setDocsWithField) throws IOException {
return getInts(reader, field, null, setDocsWithField); return getInts(reader, field, null, setDocsWithField);
} }
// inherit javadocs @Override
public Ints getInts(AtomicReader reader, String field, IntParser parser, boolean setDocsWithField) public Ints getInts(AtomicReader reader, String field, IntParser parser, boolean setDocsWithField)
throws IOException { throws IOException {
final NumericDocValues valuesIn = reader.getNumericDocValues(field); final NumericDocValues valuesIn = reader.getNumericDocValues(field);
@ -565,13 +565,13 @@ class FieldCacheImpl implements FieldCache {
} }
} }
// inherit javadocs @Override
public Floats getFloats (AtomicReader reader, String field, boolean setDocsWithField) public Floats getFloats (AtomicReader reader, String field, boolean setDocsWithField)
throws IOException { throws IOException {
return getFloats(reader, field, null, setDocsWithField); return getFloats(reader, field, null, setDocsWithField);
} }
// inherit javadocs @Override
public Floats getFloats(AtomicReader reader, String field, FloatParser parser, boolean setDocsWithField) public Floats getFloats(AtomicReader reader, String field, FloatParser parser, boolean setDocsWithField)
throws IOException { throws IOException {
final NumericDocValues valuesIn = reader.getNumericDocValues(field); final NumericDocValues valuesIn = reader.getNumericDocValues(field);
@ -671,12 +671,12 @@ class FieldCacheImpl implements FieldCache {
} }
} }
// inherit javadocs @Override
public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException { public Longs getLongs(AtomicReader reader, String field, boolean setDocsWithField) throws IOException {
return getLongs(reader, field, null, setDocsWithField); return getLongs(reader, field, null, setDocsWithField);
} }
// inherit javadocs @Override
public Longs getLongs(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField) public Longs getLongs(AtomicReader reader, String field, FieldCache.LongParser parser, boolean setDocsWithField)
throws IOException { throws IOException {
final NumericDocValues valuesIn = reader.getNumericDocValues(field); final NumericDocValues valuesIn = reader.getNumericDocValues(field);
@ -790,13 +790,13 @@ class FieldCacheImpl implements FieldCache {
} }
} }
// inherit javadocs @Override
public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField) public Doubles getDoubles(AtomicReader reader, String field, boolean setDocsWithField)
throws IOException { throws IOException {
return getDoubles(reader, field, null, setDocsWithField); return getDoubles(reader, field, null, setDocsWithField);
} }
// inherit javadocs @Override
public Doubles getDoubles(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField) public Doubles getDoubles(AtomicReader reader, String field, FieldCache.DoubleParser parser, boolean setDocsWithField)
throws IOException { throws IOException {
final NumericDocValues valuesIn = reader.getNumericDocValues(field); final NumericDocValues valuesIn = reader.getNumericDocValues(field);

View File

@ -31,13 +31,9 @@ import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueDouble; import org.apache.lucene.util.mutable.MutableValueDouble;
/** /**
* Obtains float field values from the {@link org.apache.lucene.search.FieldCache} * Obtains double field values from {@link FieldCache#getDoubles} and makes
* using <code>getFloats()</code> * those values available as other numeric types, casting as needed.
* and makes those values available as other numeric types, casting as needed.
*
*
*/ */
public class DoubleFieldSource extends FieldCacheSource { public class DoubleFieldSource extends FieldCacheSource {
protected final FieldCache.DoubleParser parser; protected final FieldCache.DoubleParser parser;

View File

@ -29,13 +29,9 @@ import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueFloat; import org.apache.lucene.util.mutable.MutableValueFloat;
/** /**
* Obtains float field values from the {@link org.apache.lucene.search.FieldCache} * Obtains float field values from {@link FieldCache#getFloats} and makes those
* using <code>getFloats()</code> * values available as other numeric types, casting as needed.
* and makes those values available as other numeric types, casting as needed.
*
*
*/ */
public class FloatFieldSource extends FieldCacheSource { public class FloatFieldSource extends FieldCacheSource {
protected final FieldCache.FloatParser parser; protected final FieldCache.FloatParser parser;

View File

@ -31,12 +31,9 @@ import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueInt; import org.apache.lucene.util.mutable.MutableValueInt;
/** /**
* Obtains int field values from the {@link org.apache.lucene.search.FieldCache} * Obtains int field values from {@link FieldCache#getInts} and makes those
* using <code>getInts()</code> * values available as other numeric types, casting as needed.
* and makes those values available as other numeric types, casting as needed. *
*
*/ */
public class IntFieldSource extends FieldCacheSource { public class IntFieldSource extends FieldCacheSource {
final FieldCache.IntParser parser; final FieldCache.IntParser parser;

View File

@ -31,13 +31,9 @@ import org.apache.lucene.util.mutable.MutableValue;
import org.apache.lucene.util.mutable.MutableValueLong; import org.apache.lucene.util.mutable.MutableValueLong;
/** /**
* Obtains float field values from the {@link org.apache.lucene.search.FieldCache} * Obtains long field values from {@link FieldCache#getLongs} and makes those
* using <code>getFloats()</code> * values available as other numeric types, casting as needed.
* and makes those values available as other numeric types, casting as needed.
*
*
*/ */
public class LongFieldSource extends FieldCacheSource { public class LongFieldSource extends FieldCacheSource {
protected final FieldCache.LongParser parser; protected final FieldCache.LongParser parser;