remove unneeded TermGenerator in MTQWF (no longer Filter.bits()). This is a small speed improvement.

I will apply this to 3.0, too, if a new RC comes.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@881984 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2009-11-18 23:01:05 +00:00
parent 03f6d7a649
commit c62fb270d6
1 changed files with 15 additions and 27 deletions

View File

@ -93,9 +93,20 @@ public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filte
public void clearTotalNumberOfTerms() {
query.clearTotalNumberOfTerms();
}
abstract class TermGenerator {
public void generate(IndexReader reader, TermEnum enumerator) throws IOException {
/**
* Returns a DocIdSet with documents that should be
* permitted in search results.
*/
@Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
final TermEnum enumerator = query.getEnum(reader);
try {
// if current term in enum is null, the enum is empty -> shortcut
if (enumerator.term() == null)
return DocIdSet.EMPTY_DOCIDSET;
// else fill into a OpenBitSet
final OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
final int[] docs = new int[32];
final int[] freqs = new int[32];
TermDocs termDocs = reader.termDocs();
@ -111,7 +122,7 @@ public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filte
final int count = termDocs.read(docs, freqs);
if (count != 0) {
for(int i=0;i<count;i++) {
handleDoc(docs[i]);
bitSet.set(docs[i]);
}
} else {
break;
@ -124,29 +135,6 @@ public class MultiTermQueryWrapperFilter<Q extends MultiTermQuery> extends Filte
} finally {
termDocs.close();
}
}
abstract public void handleDoc(int doc);
}
/**
* Returns a DocIdSet with documents that should be
* permitted in search results.
*/
@Override
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
final TermEnum enumerator = query.getEnum(reader);
try {
// if current term in enum is null, the enum is empty -> shortcut
if (enumerator.term() == null)
return DocIdSet.EMPTY_DOCIDSET;
// else fill into a OpenBitSet
final OpenBitSet bitSet = new OpenBitSet(reader.maxDoc());
new TermGenerator() {
@Override
public void handleDoc(int doc) {
bitSet.set(doc);
}
}.generate(reader, enumerator);
return bitSet;
} finally {
enumerator.close();