mirror of https://github.com/apache/lucene.git
LUCENE-1045: Applied original LUCENE-1045.patch that refactors original 1045 patch to use ExtendedFieldCache and DOES NOT make FieldCache a class
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@605225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
905674805c
commit
516143dea0
|
@ -25,17 +25,6 @@ class ExtendedFieldCacheImpl extends FieldCacheImpl implements ExtendedFieldCach
|
|||
}
|
||||
};
|
||||
|
||||
private static final ByteParser BYTE_PARSER = new ByteParser() {
|
||||
public byte parseByte(String string) {
|
||||
return Byte.parseByte(string);
|
||||
}
|
||||
};
|
||||
|
||||
private static final ShortParser SHORT_PARSER = new ShortParser() {
|
||||
public short parseShort(String string) {
|
||||
return Short.parseShort(string);
|
||||
}
|
||||
};
|
||||
|
||||
public long[] getLongs(IndexReader reader, String field) throws IOException {
|
||||
return getLongs(reader, field, LONG_PARSER);
|
||||
|
@ -114,4 +103,63 @@ class ExtendedFieldCacheImpl extends FieldCacheImpl implements ExtendedFieldCach
|
|||
return retArray;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// inherit javadocs
|
||||
public Object getAuto(IndexReader reader, String field) throws IOException {
|
||||
return autoCache.get(reader, field);
|
||||
}
|
||||
|
||||
Cache autoCache = new Cache() {
|
||||
|
||||
protected Object createValue(IndexReader reader, Object fieldKey)
|
||||
throws IOException {
|
||||
String field = ((String)fieldKey).intern();
|
||||
TermEnum enumerator = reader.terms (new Term (field, ""));
|
||||
try {
|
||||
Term term = enumerator.term();
|
||||
if (term == null) {
|
||||
throw new RuntimeException ("no terms in field " + field + " - cannot determine sort type");
|
||||
}
|
||||
Object ret = null;
|
||||
if (term.field() == field) {
|
||||
String termtext = term.text().trim();
|
||||
|
||||
/**
|
||||
* Java 1.4 level code:
|
||||
|
||||
if (pIntegers.matcher(termtext).matches())
|
||||
return IntegerSortedHitQueue.comparator (reader, enumerator, field);
|
||||
|
||||
else if (pFloats.matcher(termtext).matches())
|
||||
return FloatSortedHitQueue.comparator (reader, enumerator, field);
|
||||
*/
|
||||
|
||||
// Java 1.3 level code:
|
||||
try {
|
||||
Integer.parseInt (termtext);
|
||||
ret = getInts (reader, field);
|
||||
} catch (NumberFormatException nfe1) {
|
||||
try {
|
||||
Long.parseLong(termtext);
|
||||
ret = getLongs (reader, field);
|
||||
} catch (NumberFormatException nfe2) {
|
||||
try {
|
||||
Float.parseFloat (termtext);
|
||||
ret = getFloats (reader, field);
|
||||
} catch (NumberFormatException nfe3) {
|
||||
ret = getStringIndex (reader, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException ("field \"" + field + "\" does not appear to be indexed");
|
||||
}
|
||||
return ret;
|
||||
} finally {
|
||||
enumerator.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -21,13 +21,12 @@ import org.apache.lucene.index.IndexReader;
|
|||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.index.TermDocs;
|
||||
import org.apache.lucene.index.TermEnum;
|
||||
import org.apache.lucene.search.ExtendedFieldCache.LongParser;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Expert: The default cache implementation, storing all values in memory.
|
||||
|
@ -150,11 +149,6 @@ implements FieldCache {
|
|||
}
|
||||
};
|
||||
|
||||
private static final LongParser LONG_PARSER = new LongParser() {
|
||||
public long parseLong(String value) {
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
};
|
||||
|
||||
private static final FloatParser FLOAT_PARSER = new FloatParser() {
|
||||
public float parseFloat(String value) {
|
||||
|
@ -279,44 +273,6 @@ implements FieldCache {
|
|||
}
|
||||
};
|
||||
|
||||
// inherit javadocs
|
||||
public long[] getLongs (IndexReader reader, String field) throws IOException {
|
||||
return getLongs(reader, field, LONG_PARSER);
|
||||
}
|
||||
|
||||
// inherit javadocs
|
||||
public long[] getLongs(IndexReader reader, String field, LongParser parser)
|
||||
throws IOException {
|
||||
return (long[]) longsCache.get(reader, new Entry(field, parser));
|
||||
}
|
||||
|
||||
Cache longsCache = new Cache() {
|
||||
|
||||
protected Object createValue(IndexReader reader, Object entryKey)
|
||||
throws IOException {
|
||||
Entry entry = (Entry) entryKey;
|
||||
String field = entry.field;
|
||||
LongParser parser = (LongParser) entry.custom;
|
||||
final long[] retArray = new long[reader.maxDoc()];
|
||||
TermDocs termDocs = reader.termDocs();
|
||||
TermEnum termEnum = reader.terms (new Term (field, ""));
|
||||
try {
|
||||
do {
|
||||
Term term = termEnum.term();
|
||||
if (term==null || term.field() != field) break;
|
||||
long termval = parser.parseLong(term.text());
|
||||
termDocs.seek (termEnum);
|
||||
while (termDocs.next()) {
|
||||
retArray[termDocs.doc()] = termval;
|
||||
}
|
||||
} while (termEnum.next());
|
||||
} finally {
|
||||
termDocs.close();
|
||||
termEnum.close();
|
||||
}
|
||||
return retArray;
|
||||
}
|
||||
};
|
||||
|
||||
// inherit javadocs
|
||||
public float[] getFloats (IndexReader reader, String field)
|
||||
|
@ -500,10 +456,6 @@ implements FieldCache {
|
|||
Integer.parseInt (termtext);
|
||||
ret = getInts (reader, field);
|
||||
} catch (NumberFormatException nfe1) {
|
||||
try {
|
||||
Long.parseLong(termtext);
|
||||
ret = getLongs (reader, field);
|
||||
} catch (NumberFormatException nfe2) {
|
||||
try {
|
||||
Float.parseFloat (termtext);
|
||||
ret = getFloats (reader, field);
|
||||
|
@ -511,7 +463,6 @@ implements FieldCache {
|
|||
ret = getStringIndex (reader, field);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException ("field \"" + field + "\" does not appear to be indexed");
|
||||
}
|
||||
|
|
|
@ -417,7 +417,7 @@ extends PriorityQueue {
|
|||
static ScoreDocComparator comparatorAuto (final IndexReader reader, final String fieldname)
|
||||
throws IOException {
|
||||
final String field = fieldname.intern();
|
||||
Object lookupArray = FieldCache.DEFAULT.getAuto (reader, field);
|
||||
Object lookupArray = ExtendedFieldCache.EXT_DEFAULT.getAuto (reader, field);
|
||||
if (lookupArray instanceof FieldCache.StringIndex) {
|
||||
return comparatorString (reader, field);
|
||||
} else if (lookupArray instanceof int[]) {
|
||||
|
|
Loading…
Reference in New Issue