mirror of
https://github.com/apache/lucene.git
synced 2025-02-23 02:35:02 +00:00
Add IntParser and FloatParser interfaces to FieldCache.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@179605 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5edb98e537
commit
4ade1d4606
@ -109,6 +109,11 @@ New features
|
||||
16. Add ParallelReader, an IndexReader that combines separate indexes
|
||||
over different fields into a single virtual index. (Doug Cutting)
|
||||
|
||||
17. Add IntParser and FloatParser interfaces to FieldCache, so that
|
||||
fields in arbitrarily formats can be cached as ints and floats.
|
||||
(Doug Cutting)
|
||||
|
||||
|
||||
API Changes
|
||||
|
||||
1. Several methods and fields have been deprecated. The API documentation
|
||||
|
@ -52,6 +52,22 @@ public interface FieldCache {
|
||||
}
|
||||
}
|
||||
|
||||
/** Interface to parse ints from document fields.
|
||||
* @see #getInts(IndexReader, String, IntParser)
|
||||
*/
|
||||
public interface IntParser {
|
||||
/** Return an integer representation of this field's value. */
|
||||
public int parseInt(String string);
|
||||
}
|
||||
|
||||
|
||||
/** Interface to parse floats from document fields.
|
||||
* @see #getFloats(IndexReader, String, FloatParser)
|
||||
*/
|
||||
public interface FloatParser {
|
||||
/** Return an float representation of this field's value. */
|
||||
public float parseFloat(String string);
|
||||
}
|
||||
|
||||
/** Expert: The cache used internally by sorting and range query classes. */
|
||||
public static FieldCache DEFAULT = new FieldCacheImpl();
|
||||
@ -69,6 +85,19 @@ public interface FieldCache {
|
||||
public 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 <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.
|
||||
* @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)
|
||||
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
|
||||
@ -81,6 +110,19 @@ public interface FieldCache {
|
||||
public 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 <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.
|
||||
* @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;
|
||||
|
||||
/** Checks the internal cache for an appropriate entry, and if none
|
||||
* is found, reads the term values in <code>field</code> and returns an array
|
||||
* of size <code>reader.maxDoc()</code> containing the value each document
|
||||
|
@ -81,6 +81,17 @@ implements FieldCache {
|
||||
}
|
||||
}
|
||||
|
||||
private static final IntParser INT_PARSER = new IntParser() {
|
||||
public int parseInt(String value) {
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
};
|
||||
|
||||
private static final FloatParser FLOAT_PARSER = new FloatParser() {
|
||||
public float parseFloat(String value) {
|
||||
return Float.parseFloat(value);
|
||||
}
|
||||
};
|
||||
|
||||
/** The internal cache. Maps Entry to array of interpreted term values. **/
|
||||
final Map cache = new WeakHashMap();
|
||||
@ -132,10 +143,15 @@ implements FieldCache {
|
||||
}
|
||||
|
||||
// inherit javadocs
|
||||
public int[] getInts (IndexReader reader, String field)
|
||||
public int[] getInts (IndexReader reader, String field) throws IOException {
|
||||
return getInts(reader, field, INT_PARSER);
|
||||
}
|
||||
|
||||
// inherit javadocs
|
||||
public int[] getInts (IndexReader reader, String field, IntParser parser)
|
||||
throws IOException {
|
||||
field = field.intern();
|
||||
Object ret = lookup (reader, field, SortField.INT);
|
||||
Object ret = lookup (reader, field, parser);
|
||||
if (ret == null) {
|
||||
final int[] retArray = new int[reader.maxDoc()];
|
||||
if (retArray.length > 0) {
|
||||
@ -159,7 +175,7 @@ implements FieldCache {
|
||||
termEnum.close();
|
||||
}
|
||||
}
|
||||
store (reader, field, SortField.INT, retArray);
|
||||
store (reader, field, parser, retArray);
|
||||
return retArray;
|
||||
}
|
||||
return (int[]) ret;
|
||||
@ -167,9 +183,15 @@ implements FieldCache {
|
||||
|
||||
// inherit javadocs
|
||||
public float[] getFloats (IndexReader reader, String field)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
return getFloats(reader, field, FLOAT_PARSER);
|
||||
}
|
||||
|
||||
// inherit javadocs
|
||||
public float[] getFloats (IndexReader reader, String field,
|
||||
FloatParser parser) throws IOException {
|
||||
field = field.intern();
|
||||
Object ret = lookup (reader, field, SortField.FLOAT);
|
||||
Object ret = lookup (reader, field, parser);
|
||||
if (ret == null) {
|
||||
final float[] retArray = new float[reader.maxDoc()];
|
||||
if (retArray.length > 0) {
|
||||
@ -193,7 +215,7 @@ implements FieldCache {
|
||||
termEnum.close();
|
||||
}
|
||||
}
|
||||
store (reader, field, SortField.FLOAT, retArray);
|
||||
store (reader, field, parser, retArray);
|
||||
return retArray;
|
||||
}
|
||||
return (float[]) ret;
|
||||
@ -388,7 +410,7 @@ implements FieldCache {
|
||||
termEnum.close();
|
||||
}
|
||||
}
|
||||
store (reader, field, SortField.CUSTOM, retArray);
|
||||
store (reader, field, comparator, retArray);
|
||||
return retArray;
|
||||
}
|
||||
return (Comparable[]) ret;
|
||||
|
Loading…
x
Reference in New Issue
Block a user