getFloats()
@@ -39,23 +38,27 @@
*
*/
-public class DoubleFieldSource extends NumericFieldCacheSourcegetFloats()
@@ -40,12 +38,19 @@
*
*/
-public class LongFieldSource extends NumericFieldCacheSourcegetInts()
@@ -32,12 +31,19 @@
*
*/
-public class ByteFieldSource extends NumericFieldCacheSourcegetInts()
@@ -38,12 +37,18 @@
*
*/
-public class IntFieldSource extends NumericFieldCacheSourcereader.maxDoc(), with turned on bits for each docid that
+ * does have a value for this field.
+ */
+ public 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 as a single byte and returns an array
* of size reader.maxDoc() of the value each document
* has in the given field.
* @param reader Used to get field values.
* @param field Which field contains the single byte 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 byte[] getBytes (IndexReader reader, String field)
+ public byte[] getBytes (IndexReader reader, String field, boolean setDocsWithField)
throws IOException;
/** Checks the internal cache for an appropriate entry, and if none is found,
@@ -318,35 +327,26 @@
* @param reader Used to get field values.
* @param field Which field contains the bytes.
* @param parser Computes byte 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 byte[] getBytes (IndexReader reader, String field, ByteParser parser)
+ public byte[] getBytes (IndexReader reader, String field, 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.
- * @param reader Used to get field values.
- * @param field Which field contains the bytes.
- * @param creator Used to make the ByteValues
- * @return The values in the given field for each document.
- * @throws IOException If any error occurs.
- */
- public ByteValues getBytes(IndexReader reader, String field, EntryCreatorfield as shorts and returns an array
* of size reader.maxDoc() of the value each document
* has in the given field.
* @param reader Used to get field values.
* @param field Which field contains the shorts.
+ * @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 short[] getShorts (IndexReader reader, String field)
+ public short[] getShorts (IndexReader reader, String field, boolean setDocsWithField)
throws IOException;
/** Checks the internal cache for an appropriate entry, and if none is found,
@@ -356,36 +356,26 @@
* @param reader Used to get field values.
* @param field Which field contains the shorts.
* @param parser Computes short 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 short[] getShorts (IndexReader reader, String field, ShortParser parser)
+ public short[] getShorts (IndexReader reader, String field, 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.
- * @param reader Used to get field values.
- * @param field Which field contains the shorts.
- * @param creator Computes short for string values.
- * @return The values in the given field for each document.
- * @throws IOException If any error occurs.
- */
- public ShortValues getShorts(IndexReader reader, String field, EntryCreatorfield as integers and returns an array
* of size reader.maxDoc() 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.
*/
- public int[] getInts (IndexReader reader, String field)
+ public int[] getInts (IndexReader reader, String field, boolean setDocsWithField)
throws IOException;
/** Checks the internal cache for an appropriate entry, and if none is found,
@@ -395,35 +385,26 @@
* @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.
* @return The values in the given field for each document.
* @throws IOException If any error occurs.
*/
- public int[] getInts (IndexReader reader, String field, IntParser parser)
+ public int[] getInts (IndexReader 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 field as integers and returns an array of
- * size reader.maxDoc() 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 creator Computes integer for string values.
- * @return The values in the given field for each document.
- * @throws IOException If any error occurs.
- */
- public IntValues getInts(IndexReader reader, String field, EntryCreatorfield as floats and returns an array
* of size reader.maxDoc() 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.
*/
- public float[] getFloats (IndexReader reader, String field)
+ public float[] getFloats (IndexReader reader, String field, boolean setDocsWithField)
throws IOException;
/** Checks the internal cache for an appropriate entry, and if
@@ -433,25 +414,14 @@
* @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.
* @return The values in the given field for each document.
* @throws IOException If any error occurs.
*/
public float[] getFloats (IndexReader reader, String field,
- FloatParser parser) throws IOException;
+ 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.
- * @param reader Used to get field values.
- * @param field Which field contains the floats.
- * @param creator Computes float for string values.
- * @return The values in the given field for each document.
- * @throws IOException If any error occurs.
- */
- public FloatValues getFloats(IndexReader reader, String field, EntryCreatorfield as longs and returns an array
@@ -460,10 +430,12 @@
*
* @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.
*/
- public long[] getLongs(IndexReader reader, String field)
+ public long[] getLongs(IndexReader reader, String field, boolean setDocsWithField)
throws IOException;
/**
@@ -475,28 +447,15 @@
* @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.
* @return The values in the given field for each document.
* @throws IOException If any error occurs.
*/
- public long[] getLongs(IndexReader reader, String field, LongParser parser)
+ public long[] getLongs(IndexReader 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 field as longs and returns an array of
- * size reader.maxDoc() 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 creator Computes integer for string values.
- * @return The values in the given field for each document.
- * @throws IOException If any error occurs.
- */
- public LongValues getLongs(IndexReader reader, String field, EntryCreatorfield as integers and returns an array
* of size reader.maxDoc() of the value each document
@@ -504,10 +463,12 @@
*
* @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.
*/
- public double[] getDoubles(IndexReader reader, String field)
+ public double[] getDoubles(IndexReader reader, String field, boolean setDocsWithField)
throws IOException;
/**
@@ -519,27 +480,14 @@
* @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 double[] getDoubles(IndexReader reader, String field, DoubleParser parser)
+ public double[] getDoubles(IndexReader reader, String field, 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.
- *
- * @param reader Used to get field values.
- * @param field Which field contains the doubles.
- * @param creator Computes integer for string values.
- * @return The values in the given field for each document.
- * @throws IOException If any error occurs.
- */
- public DoubleValues getDoubles(IndexReader reader, String field, EntryCreatornull if
@@ -141,10 +142,7 @@
* by testing which numeric parser the parser subclasses.
* @throws IllegalArgumentException if the parser fails to
* subclass an existing numeric parser, or field is null
- *
- * @deprecated (4.0) use EntryCreator version
*/
- @Deprecated
public SortField(String field, FieldCache.Parser parser) {
this(field, parser, false);
}
@@ -159,65 +157,27 @@
* @param reverse True if natural order should be reversed.
* @throws IllegalArgumentException if the parser fails to
* subclass an existing numeric parser, or field is null
- *
- * @deprecated (4.0) use EntryCreator version
*/
- @Deprecated
public SortField(String field, FieldCache.Parser parser, boolean reverse) {
- if (field == null) {
- throw new IllegalArgumentException("field can only be null when type is SCORE or DOC");
- }
- this.field = field;
- this.reverse = reverse;
-
- if (parser instanceof FieldCache.IntParser) {
- this.creator = new IntValuesCreator( field, (FieldCache.IntParser)parser );
- }
- else if (parser instanceof FieldCache.FloatParser) {
- this.creator = new FloatValuesCreator( field, (FieldCache.FloatParser)parser );
- }
- else if (parser instanceof FieldCache.ShortParser) {
- this.creator = new ShortValuesCreator( field, (FieldCache.ShortParser)parser );
- }
- else if (parser instanceof FieldCache.ByteParser) {
- this.creator = new ByteValuesCreator( field, (FieldCache.ByteParser)parser );
- }
- else if (parser instanceof FieldCache.LongParser) {
- this.creator = new LongValuesCreator( field, (FieldCache.LongParser)parser );
- }
- else if (parser instanceof FieldCache.DoubleParser) {
- this.creator = new DoubleValuesCreator( field, (FieldCache.DoubleParser)parser );
- }
- else
+ if (parser instanceof FieldCache.IntParser) initFieldType(field, Type.INT);
+ else if (parser instanceof FieldCache.FloatParser) initFieldType(field, Type.FLOAT);
+ else if (parser instanceof FieldCache.ShortParser) initFieldType(field, Type.SHORT);
+ else if (parser instanceof FieldCache.ByteParser) initFieldType(field, Type.BYTE);
+ else if (parser instanceof FieldCache.LongParser) initFieldType(field, Type.LONG);
+ else if (parser instanceof FieldCache.DoubleParser) initFieldType(field, Type.DOUBLE);
+ else {
throw new IllegalArgumentException("Parser instance does not subclass existing numeric parser from FieldCache (got " + parser + ")");
+ }
- this.type = this.creator.getSortType();
- }
-
- /**
- * Sort by a cached entry value
- * @param creator
- * @param reverse
- */
- public SortField( CachedArrayCreator> creator, boolean reverse )
- {
- this.field = creator.field;
this.reverse = reverse;
- this.creator = creator;
- this.type = creator.getSortType();
+ this.parser = parser;
}
- public SortField setMissingValue( Object v )
- {
- missingValue = v;
- if( missingValue != null ) {
- if( this.creator == null ) {
- throw new IllegalArgumentException( "Missing value only works for sort fields with a CachedArray" );
- }
-
- // Set the flag to get bits
- creator.setFlag( CachedArrayCreator.OPTION_CACHE_BITS );
+ public SortField setMissingValue(Object missingValue) {
+ if (type != Type.BYTE && type != Type.SHORT && type != Type.INT && type != Type.FLOAT && type != Type.LONG && type != Type.DOUBLE) {
+ throw new IllegalArgumentException( "Missing value only works for numeric types" );
}
+ this.missingValue = missingValue;
return this;
}
@@ -246,23 +206,12 @@
private void initFieldType(String field, Type type) {
this.type = type;
if (field == null) {
- if (type != Type.SCORE && type != Type.DOC)
+ if (type != Type.SCORE && type != Type.DOC) {
throw new IllegalArgumentException("field can only be null when type is SCORE or DOC");
+ }
} else {
this.field = field;
}
-
- if( creator != null ) {
- throw new IllegalStateException( "creator already exists: "+creator );
- }
- switch( type ) {
- case BYTE: creator = new ByteValuesCreator( field, null ); break;
- case SHORT: creator = new ShortValuesCreator( field, null ); break;
- case INT: creator = new IntValuesCreator( field, null ); break;
- case LONG: creator = new LongValuesCreator( field, null ); break;
- case FLOAT: creator = new FloatValuesCreator( field, null ); break;
- case DOUBLE: creator = new DoubleValuesCreator( field, null ); break;
- }
}
/** Returns the name of the field. Could return null
@@ -283,17 +232,11 @@
/** Returns the instance of a {@link FieldCache} parser that fits to the given sort type.
* May return null if no parser was specified. Sorting is using the default parser then.
* @return An instance of a {@link FieldCache} parser, or null.
- * @deprecated (4.0) use getEntryCreator()
*/
- @Deprecated
public FieldCache.Parser getParser() {
- return (creator==null) ? null : creator.getParser();
+ return parser;
}
- public CachedArrayCreator> getEntryCreator() {
- return creator;
- }
-
/** Returns whether the sort should be reversed.
* @return True if natural order should be reversed.
*/
@@ -365,7 +308,6 @@
break;
}
- if (creator != null) buffer.append('(').append(creator).append(')');
if (reverse) buffer.append('!');
return buffer.toString();
@@ -385,7 +327,6 @@
&& other.type == this.type
&& other.reverse == this.reverse
&& (other.comparatorSource == null ? this.comparatorSource == null : other.comparatorSource.equals(this.comparatorSource))
- && (other.creator == null ? this.creator == null : other.creator.equals(this.creator))
);
}
@@ -399,7 +340,6 @@
int hash = type.hashCode() ^ 0x346565dd + Boolean.valueOf(reverse).hashCode() ^ 0xaf5998bb;
if (field != null) hash += field.hashCode()^0xff5685dd;
if (comparatorSource != null) hash += comparatorSource.hashCode();
- if (creator != null) hash += creator.hashCode()^0x3aaf56ff;
return hash;
}
@@ -448,27 +388,27 @@
if (useIndexValues) {
return new FieldComparator.IntDocValuesComparator(numHits, field);
} else {
- return new FieldComparator.IntComparator(numHits, (IntValuesCreator)creator, (Integer) missingValue);
+ return new FieldComparator.IntComparator(numHits, field, parser, (Integer) missingValue);
}
case FLOAT:
if (useIndexValues) {
return new FieldComparator.FloatDocValuesComparator(numHits, field);
} else {
- return new FieldComparator.FloatComparator(numHits, (FloatValuesCreator) creator, (Float) missingValue);
+ return new FieldComparator.FloatComparator(numHits, field, parser, (Float) missingValue);
}
case LONG:
- return new FieldComparator.LongComparator(numHits, (LongValuesCreator)creator, (Long)missingValue );
+ return new FieldComparator.LongComparator(numHits, field, parser, (Long) missingValue);
case DOUBLE:
- return new FieldComparator.DoubleComparator(numHits, (DoubleValuesCreator)creator, (Double)missingValue );
+ return new FieldComparator.DoubleComparator(numHits, field, parser, (Double) missingValue);
case BYTE:
- return new FieldComparator.ByteComparator(numHits, (ByteValuesCreator)creator, (Byte)missingValue );
+ return new FieldComparator.ByteComparator(numHits, field, parser, (Byte) missingValue);
case SHORT:
- return new FieldComparator.ShortComparator(numHits, (ShortValuesCreator)creator, (Short)missingValue );
+ return new FieldComparator.ShortComparator(numHits, field, parser, (Short) missingValue);
case CUSTOM:
assert comparatorSource != null;
Index: lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java
===================================================================
--- lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java (revision 1199903)
+++ lucene/src/java/org/apache/lucene/search/FieldCacheImpl.java (working copy)
@@ -17,28 +17,42 @@
* limitations under the License.
*/
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
+
import org.apache.lucene.index.DocTermOrds;
+import org.apache.lucene.index.DocsAndPositionsEnum;
+import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.search.cache.*;
-import org.apache.lucene.search.cache.CachedArray.*;
+import org.apache.lucene.index.MultiFields;
+import org.apache.lucene.index.OrdTermState;
+import org.apache.lucene.index.TermState;
+import org.apache.lucene.index.Terms;
+import org.apache.lucene.index.TermsEnum;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.Bits;
+import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.FieldCacheSanityChecker;
+import org.apache.lucene.util.FixedBitSet;
+import org.apache.lucene.util.PagedBytes;
+import org.apache.lucene.util.packed.GrowableWriter;
+import org.apache.lucene.util.packed.PackedInts;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.*;
-
/**
* Expert: The default cache implementation, storing all values in memory.
* A WeakHashMap is used for storage.
*
* Created: May 19, 2004 4:40:36 PM
- *
- * @lucene.internal -- this is now public so that the tests can use reflection
- * to call methods. It will likely be removed without (much) notice.
- *
+ *
* @since lucene 1.4
*/
-public class FieldCacheImpl implements FieldCache { // Made Public so that
+class FieldCacheImpl implements FieldCache {
private Map