Removed constrait that a sort field must have some terms indexed: LUCENE-374

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@377502 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2006-02-13 21:46:13 +00:00
parent 93657ca63a
commit 8a3cae2dd8
2 changed files with 100 additions and 121 deletions

View File

@ -337,6 +337,9 @@ Bug fixes
"[1/16/2000 TO 1/18/2000]". This query did not include the documents "[1/16/2000 TO 1/18/2000]". This query did not include the documents
of 1/18/2000, i.e. the last day was not included. (Daniel Naber) of 1/18/2000, i.e. the last day was not included. (Daniel Naber)
24. Removed sorting constraint that threw an exception if there were
not yet any values for the sort field (Yonik Seeley, LUCENE-374)
Optimizations Optimizations
1. Disk usage (peak requirements during indexing and optimization) 1. Disk usage (peak requirements during indexing and optimization)

View File

@ -154,26 +154,21 @@ implements FieldCache {
Object ret = lookup (reader, field, parser); Object ret = lookup (reader, field, parser);
if (ret == null) { if (ret == null) {
final int[] retArray = new int[reader.maxDoc()]; final int[] retArray = new int[reader.maxDoc()];
if (retArray.length > 0) { TermDocs termDocs = reader.termDocs();
TermDocs termDocs = reader.termDocs(); TermEnum termEnum = reader.terms (new Term (field, ""));
TermEnum termEnum = reader.terms (new Term (field, "")); try {
try { do {
if (termEnum.term() == null) { Term term = termEnum.term();
throw new RuntimeException ("no terms in field " + field); if (term==null || term.field() != field) break;
int termval = parser.parseInt(term.text());
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
} }
do { } while (termEnum.next());
Term term = termEnum.term(); } finally {
if (term.field() != field) break; termDocs.close();
int termval = parser.parseInt(term.text()); termEnum.close();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
} finally {
termDocs.close();
termEnum.close();
}
} }
store (reader, field, parser, retArray); store (reader, field, parser, retArray);
return retArray; return retArray;
@ -194,26 +189,21 @@ implements FieldCache {
Object ret = lookup (reader, field, parser); Object ret = lookup (reader, field, parser);
if (ret == null) { if (ret == null) {
final float[] retArray = new float[reader.maxDoc()]; final float[] retArray = new float[reader.maxDoc()];
if (retArray.length > 0) { TermDocs termDocs = reader.termDocs();
TermDocs termDocs = reader.termDocs(); TermEnum termEnum = reader.terms (new Term (field, ""));
TermEnum termEnum = reader.terms (new Term (field, "")); try {
try { do {
if (termEnum.term() == null) { Term term = termEnum.term();
throw new RuntimeException ("no terms in field " + field); if (term==null || term.field() != field) break;
float termval = parser.parseFloat(term.text());
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
} }
do { } while (termEnum.next());
Term term = termEnum.term(); } finally {
if (term.field() != field) break; termDocs.close();
float termval = parser.parseFloat(term.text()); termEnum.close();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
} finally {
termDocs.close();
termEnum.close();
}
} }
store (reader, field, parser, retArray); store (reader, field, parser, retArray);
return retArray; return retArray;
@ -228,26 +218,21 @@ implements FieldCache {
Object ret = lookup (reader, field, SortField.STRING); Object ret = lookup (reader, field, SortField.STRING);
if (ret == null) { if (ret == null) {
final String[] retArray = new String[reader.maxDoc()]; final String[] retArray = new String[reader.maxDoc()];
if (retArray.length > 0) { TermDocs termDocs = reader.termDocs();
TermDocs termDocs = reader.termDocs(); TermEnum termEnum = reader.terms (new Term (field, ""));
TermEnum termEnum = reader.terms (new Term (field, "")); try {
try { do {
if (termEnum.term() == null) { Term term = termEnum.term();
throw new RuntimeException ("no terms in field " + field); if (term==null || term.field() != field) break;
String termval = term.text();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
} }
do { } while (termEnum.next());
Term term = termEnum.term(); } finally {
if (term.field() != field) break; termDocs.close();
String termval = term.text(); termEnum.close();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
} finally {
termDocs.close();
termEnum.close();
}
} }
store (reader, field, SortField.STRING, retArray); store (reader, field, SortField.STRING, retArray);
return retArray; return retArray;
@ -263,56 +248,52 @@ implements FieldCache {
if (ret == null) { if (ret == null) {
final int[] retArray = new int[reader.maxDoc()]; final int[] retArray = new int[reader.maxDoc()];
String[] mterms = new String[reader.maxDoc()+1]; String[] mterms = new String[reader.maxDoc()+1];
if (retArray.length > 0) { TermDocs termDocs = reader.termDocs();
TermDocs termDocs = reader.termDocs(); TermEnum termEnum = reader.terms (new Term (field, ""));
TermEnum termEnum = reader.terms (new Term (field, "")); int t = 0; // current term number
int t = 0; // current term number
// an entry for documents that have no terms in this field // an entry for documents that have no terms in this field
// should a document with no terms be at top or bottom? // should a document with no terms be at top or bottom?
// this puts them at the top - if it is changed, FieldDocSortedHitQueue // this puts them at the top - if it is changed, FieldDocSortedHitQueue
// needs to change as well. // needs to change as well.
mterms[t++] = null; mterms[t++] = null;
try { try {
if (termEnum.term() == null) { do {
throw new RuntimeException ("no terms in field " + field); Term term = termEnum.term();
if (term==null || term.field() != field) break;
// store term text
// we expect that there is at most one term per document
if (t >= mterms.length) throw new RuntimeException ("there are more terms than " +
"documents in field \"" + field + "\", but it's impossible to sort on " +
"tokenized fields");
mterms[t] = term.text();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = t;
} }
do {
Term term = termEnum.term();
if (term.field() != field) break;
// store term text t++;
// we expect that there is at most one term per document } while (termEnum.next());
if (t >= mterms.length) throw new RuntimeException ("there are more terms than " + } finally {
"documents in field \"" + field + "\", but it's impossible to sort on " + termDocs.close();
"tokenized fields"); termEnum.close();
mterms[t] = term.text();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = t;
}
t++;
} while (termEnum.next());
} finally {
termDocs.close();
termEnum.close();
}
if (t == 0) {
// if there are no terms, make the term array
// have a single null entry
mterms = new String[1];
} else if (t < mterms.length) {
// if there are less terms than documents,
// trim off the dead array space
String[] terms = new String[t];
System.arraycopy (mterms, 0, terms, 0, t);
mterms = terms;
}
} }
if (t == 0) {
// if there are no terms, make the term array
// have a single null entry
mterms = new String[1];
} else if (t < mterms.length) {
// if there are less terms than documents,
// trim off the dead array space
String[] terms = new String[t];
System.arraycopy (mterms, 0, terms, 0, t);
mterms = terms;
}
StringIndex value = new StringIndex (retArray, mterms); StringIndex value = new StringIndex (retArray, mterms);
store (reader, field, STRING_INDEX, value); store (reader, field, STRING_INDEX, value);
return value; return value;
@ -389,26 +370,21 @@ implements FieldCache {
Object ret = lookup (reader, field, comparator); Object ret = lookup (reader, field, comparator);
if (ret == null) { if (ret == null) {
final Comparable[] retArray = new Comparable[reader.maxDoc()]; final Comparable[] retArray = new Comparable[reader.maxDoc()];
if (retArray.length > 0) { TermDocs termDocs = reader.termDocs();
TermDocs termDocs = reader.termDocs(); TermEnum termEnum = reader.terms (new Term (field, ""));
TermEnum termEnum = reader.terms (new Term (field, "")); try {
try { do {
if (termEnum.term() == null) { Term term = termEnum.term();
throw new RuntimeException ("no terms in field " + field); if (term==null || term.field() != field) break;
Comparable termval = comparator.getComparable (term.text());
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
} }
do { } while (termEnum.next());
Term term = termEnum.term(); } finally {
if (term.field() != field) break; termDocs.close();
Comparable termval = comparator.getComparable (term.text()); termEnum.close();
termDocs.seek (termEnum);
while (termDocs.next()) {
retArray[termDocs.doc()] = termval;
}
} while (termEnum.next());
} finally {
termDocs.close();
termEnum.close();
}
} }
store (reader, field, comparator, retArray); store (reader, field, comparator, retArray);
return retArray; return retArray;