From 278dc0fc0415263c68ce9db5c7644765a37359e1 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 1 Dec 2008 18:50:45 +0000 Subject: [PATCH] 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 --- CHANGES.txt | 4 ++++ .../src/java/org/apache/lucene/misc/ChainedFilter.java | 9 +++++++-- .../java/org/apache/lucene/search/BooleanFilter.java | 9 ++++++--- .../org/apache/lucene/search/CachingWrapperFilter.java | 10 +++++++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 904d2a67ee7..e1c098be5ab 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java b/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java index 097b9ccb052..0731c4bb241 100644 --- a/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java +++ b/contrib/miscellaneous/src/java/org/apache/lucene/misc/ChainedFilter.java @@ -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) diff --git a/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java b/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java index 552d1b2a539..c3c22f86255 100644 --- a/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java +++ b/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java @@ -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) diff --git a/src/java/org/apache/lucene/search/CachingWrapperFilter.java b/src/java/org/apache/lucene/search/CachingWrapperFilter.java index 52d2b5d0f9c..4efeb40f35c 100644 --- a/src/java/org/apache/lucene/search/CachingWrapperFilter.java +++ b/src/java/org/apache/lucene/search/CachingWrapperFilter.java @@ -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);