LUCENE-1296: add protected method CachingWrapperFilter.docIdSetToCache

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@722174 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2008-12-01 18:50:45 +00:00
parent 371a33eda8
commit 278dc0fc04
4 changed files with 26 additions and 6 deletions

View File

@ -105,6 +105,10 @@ New features
slower first-time usage due to populating the FieldCache. (Tim
Sturge via Mike McCandless)
8. LUCENE-1296: add protected method CachingWrapperFilter.docIdSetToCache
to allow subclasses to choose which DocIdSet implementation to use
(Paul Elschot via Mike McCandless)
Optimizations
1. LUCENE-1427: Fixed QueryWrapperFilter to not waste time computing

View File

@ -176,8 +176,13 @@ public class ChainedFilter extends Filter
}
return result;
}
/** Provide a SortedVIntList when it is definitely smaller than an OpenBitSet */
// TODO: in 3.0, instead of removing this deprecated
// method, make it a no-op and mark it final
/** Provide a SortedVIntList when it is definitely
* smaller than an OpenBitSet
* @deprecated Either use CachingWrapperFilter, or
* switch to a different DocIdSet implementation yourself. */
protected DocIdSet finalResult(OpenBitSetDISI result, int maxDocs) {
return (result.cardinality() < (maxDocs / 9))
? (DocIdSet) new SortedVIntList(result)

View File

@ -19,11 +19,9 @@ package org.apache.lucene.search;
import java.io.IOException;
import java.util.ArrayList;
import java.util.BitSet;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.util.DocIdBitSet;
import org.apache.lucene.util.OpenBitSet;
import org.apache.lucene.util.OpenBitSetDISI;
import org.apache.lucene.util.SortedVIntList;
@ -116,7 +114,12 @@ public class BooleanFilter extends Filter
return emptyDocIdSet;
}
/** Provide a SortedVIntList when it is definitely smaller than an OpenBitSet */
// TODO: in 3.0, instead of removing this deprecated
// method, make it a no-op and mark it final
/** Provide a SortedVIntList when it is definitely smaller
* than an OpenBitSet.
* @deprecated Either use CachingWrapperFilter, or
* switch to a different DocIdSet implementation yourself. */
protected DocIdSet finalResult(OpenBitSetDISI result, int maxDocs) {
return (result.cardinality() < (maxDocs / 9))
? (DocIdSet) new SortedVIntList(result)

View File

@ -73,6 +73,14 @@ public class CachingWrapperFilter extends Filter {
return bits;
}
/** Provide the DocIdSet to be cached, using the DocIdSet provided
* by the wrapped Filter.
* This implementation returns the given DocIdSet.
*/
protected DocIdSet docIdSetToCache(DocIdSet docIdSet, IndexReader reader) {
return docIdSet;
}
public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
if (cache == null) {
@ -91,7 +99,7 @@ public class CachingWrapperFilter extends Filter {
return new DocIdBitSet((BitSet) cached);
}
final DocIdSet docIdSet = filter.getDocIdSet(reader);
final DocIdSet docIdSet = docIdSetToCache(filter.getDocIdSet(reader), reader);
synchronized (cache) { // update cache
cache.put(reader, docIdSet);