lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r950612 - in /lucene/java/branches/lucene_2_9: ./ contrib/ contrib/analyzers/ contrib/highlighter/src/test/ contrib/instantiated/src/test/org/apache/lucene/store/instantiated/ src/java/org/apache/lucene/analysis/ src/java/org/apache/lucene/...
Date Wed, 02 Jun 2010 16:03:19 GMT
Author: mikemccand
Date: Wed Jun  2 16:03:19 2010
New Revision: 950612

URL: http://svn.apache.org/viewvc?rev=950612&view=rev
Log:
LUCENE-2468: allow specifying how CachingWrapper/SpanFilter should handle deletions on reopened
readers

Added:
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
      - copied unchanged from r950580, lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/search/TestCachingSpanFilter.java
Modified:
    lucene/java/branches/lucene_2_9/   (props changed)
    lucene/java/branches/lucene_2_9/CHANGES.txt   (contents, props changed)
    lucene/java/branches/lucene_2_9/build.xml   (props changed)
    lucene/java/branches/lucene_2_9/contrib/   (props changed)
    lucene/java/branches/lucene_2_9/contrib/CHANGES.txt   (props changed)
    lucene/java/branches/lucene_2_9/contrib/analyzers/   (props changed)
    lucene/java/branches/lucene_2_9/contrib/highlighter/src/test/   (props changed)
    lucene/java/branches/lucene_2_9/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/analysis/Tokenizer.java   (props
changed)
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/FilterIndexReader.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexReader.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentReader.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingSpanFilter.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingWrapperFilter.java
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java 
 (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestDateTools.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestNumberTools.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/   (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
  (props changed)
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/CachingWrapperFilterHelper.java
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
    lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java
  (props changed)

Propchange: lucene/java/branches/lucene_2_9/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,5 +1,5 @@
 /lucene/dev/branches/branch_3x/lucene:941394,946651,948430
-/lucene/dev/trunk/lucene:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
+/lucene/dev/trunk/lucene:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
 /lucene/java/branches/lucene_2_4:748824
-/lucene/java/branches/lucene_3_0:886275,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/java/branches/lucene_3_0:886275,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk:821888,824125,826029,826385,830871,833095,833297,833886,834035,836155,881819,882672,883554,884870,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Modified: lucene/java/branches/lucene_2_9/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/CHANGES.txt?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_9/CHANGES.txt Wed Jun  2 16:03:19 2010
@@ -76,6 +76,18 @@ Bug fixes
 * LUCENE-2478: Fix CachingWrapperFilter to not throw NPE when
   Filter.getDocIdSet() returns null.  (Uwe Schindler, Daniel Noll)
 
+* LUCENE-2468: Allow specifying how new deletions should be handled in
+  CachingWrapperFilter and CachingSpanFilter.  By default, new
+  deletions are ignored in CachingWrapperFilter, since typically this
+  filter is AND'd with a query that correctly takes new deletions into
+  account.  This should be a performance gain (higher cache hit rate)
+  in apps that reopen readers, or use near-real-time reader
+  (IndexWriter.getReader()), but may introduce invalid search results
+  (allowing deleted docs to be returned) for certain cases, so a new
+  expert ctor was added to CachingWrapperFilter to enforce deletions
+  at a performance cost.  CachingSpanFilter by default recaches if
+  there are new deletions (Shay Banon via Mike McCandless)
+
 * LUCENE-2299: If you open an NRT reader while addIndexes* is running,
   it may miss some segments (Earwin Burrfoot via Mike McCandless)
 

Propchange: lucene/java/branches/lucene_2_9/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/CHANGES.txt:941394,946651,948430
-/lucene/dev/trunk/lucene/CHANGES.txt:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/CHANGES.txt:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/CHANGES.txt:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/CHANGES.txt:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/CHANGES.txt:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/build.xml
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/build.xml:941394,946651,948430
-/lucene/dev/trunk/lucene/build.xml:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/build.xml:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/build.xml:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/build.xml:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/build.xml:821888,834035,836155,887670,889431-889432,889579,889866,890439,891205,891209,891377,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/contrib/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/contrib:941394,946651,948430
-/lucene/dev/trunk/lucene/contrib:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/contrib:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/contrib:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/contrib:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/contrib:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/contrib/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/contrib/CHANGES.txt:941394,946651,948430
-/lucene/dev/trunk/lucene/contrib/CHANGES.txt:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/contrib/CHANGES.txt:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/contrib/CHANGES.txt:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/contrib/CHANGES.txt:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/contrib/CHANGES.txt:821888,834035,836155,887670,889431-889432,889579,889866,890439,891205,891209,891377,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/contrib/analyzers/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/contrib/analyzers:941394,946651
-/lucene/dev/trunk/lucene/contrib/analyzers:939611,940730,950458
-/lucene/java/branches/lucene_3_0/contrib/analyzers:950301,950474
+/lucene/dev/trunk/lucene/contrib/analyzers:939611,940730,949288,950458
+/lucene/java/branches/lucene_3_0/contrib/analyzers:950301,950474,950580
 /lucene/java/trunk/contrib/analyzers:834035,836155,887670,889579,889866,890439,891205,891377,920270

Propchange: lucene/java/branches/lucene_2_9/contrib/highlighter/src/test/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/contrib/highlighter/src/test:941394,946651,948430
-/lucene/dev/trunk/lucene/contrib/highlighter/src/test:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/contrib/highlighter/src/test:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/contrib/highlighter/src/test:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/contrib/highlighter/src/test:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/contrib/highlighter/src/test:821888,834035,836155,887670,889431-889432,889579,889866,890439,891205,891209,891377,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,7 +1,7 @@
 /lucene/dev/branches/branch_3x/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:941394,946651,948430
-/lucene/dev/trunk/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
+/lucene/dev/trunk/lucene/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
 /lucene/java/branches/lucene_2_4/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:748824
 /lucene/java/branches/lucene_2_9/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:817269-818599
 /lucene/java/branches/lucene_2_9_back_compat_tests/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:818601-821336
-/lucene/java/branches/lucene_3_0/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:889463,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/java/branches/lucene_3_0/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:889463,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/contrib/instantiated/src/test/org/apache/lucene/store/instantiated/TestIndicesEquals.java:821888,834035,836155,881213,881315,881466,881819,882374,882672,882807,882888,882977,883074-883075,883554,884870,886257,886911,887347,887532,887602,887670,888247,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/analysis/Tokenizer.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/analysis/Tokenizer.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Tokenizer.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/analysis/Tokenizer.java:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/java/org/apache/lucene/analysis/Tokenizer.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/analysis/Tokenizer.java:889688,891211,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/java/org/apache/lucene/analysis/Tokenizer.java:821888,834035,836155,887670,889579,889866,890439,891205,891377,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/FilterIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/FilterIndexReader.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/FilterIndexReader.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/FilterIndexReader.java
Wed Jun  2 16:03:19 2010
@@ -256,4 +256,11 @@ public class FilterIndexReader extends I
   public Object getFieldCacheKey() {
     return in.getFieldCacheKey();
   }
+
+  /** If the subclass of FilteredIndexReader modifies the
+   *  deleted docs, you must override this method to provide
+   *  a different key */
+  public Object getDeletesCacheKey() {
+    return in.getDeletesCacheKey();
+  }
 }

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexReader.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexReader.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/IndexReader.java Wed
Jun  2 16:03:19 2010
@@ -1495,6 +1495,12 @@ public abstract class IndexReader implem
     return this;
   }
 
+  /** Expert.  Warning: this returns null if the reader has
+   *  no deletions */
+  public Object getDeletesCacheKey() {
+    return this;
+  }
+
   /** Returns the number of unique terms (across all fields)
    *  in this reader.
    *

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentReader.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentReader.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentReader.java (original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/index/SegmentReader.java Wed
Jun  2 16:03:19 2010
@@ -1349,6 +1349,10 @@ public class SegmentReader extends Index
     return core.freqStream;
   }
 
+  public Object getDeletesCacheKey() {
+    return deletedDocs;
+  }
+
   public long getUniqueTermCount() {
     return core.getTermsReader().size();
   }

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingSpanFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingSpanFilter.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingSpanFilter.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingSpanFilter.java
Wed Jun  2 16:03:19 2010
@@ -20,8 +20,6 @@ import org.apache.lucene.index.IndexRead
 
 import java.io.IOException;
 import java.util.BitSet;
-import java.util.Map;
-import java.util.WeakHashMap;
 
 /**
  * Wraps another SpanFilter's result and caches it.  The purpose is to allow
@@ -33,13 +31,31 @@ public class CachingSpanFilter extends S
   /**
    * A transient Filter cache.
    */
-  protected transient Map cache;
+  private final CachingWrapperFilter.FilterCache cache;
 
   /**
+   * New deletions always result in a cache miss, by default
+   * ({@link CachingWrapperFilter.DeletesMode#RECACHE}.
    * @param filter Filter to cache results of
    */
   public CachingSpanFilter(SpanFilter filter) {
+    this(filter, CachingWrapperFilter.DeletesMode.RECACHE);
+  }
+
+  /**
+   * @param filter Filter to cache results of
+   * @param deletesMode See {@link CachingWrapperFilter.DeletesMode}
+   */
+  public CachingSpanFilter(SpanFilter filter, CachingWrapperFilter.DeletesMode deletesMode)
{
     this.filter = filter;
+    if (deletesMode == CachingWrapperFilter.DeletesMode.DYNAMIC) {
+      throw new IllegalArgumentException("DeletesMode.DYNAMIC is not supported");
+    }
+    this.cache = new CachingWrapperFilter.FilterCache(deletesMode) {
+      protected Object mergeDeletes(final IndexReader r, final Object value) {
+        throw new IllegalStateException("DeletesMode.DYNAMIC is not supported");
+      }
+    };
   }
 
   /**
@@ -55,19 +71,24 @@ public class CachingSpanFilter extends S
     return result != null ? result.getDocIdSet() : null;
   }
   
+  // for testing
+  int hitCount, missCount;
+
   private SpanFilterResult getCachedResult(IndexReader reader) throws IOException {
-    SpanFilterResult result = null;
-    if (cache == null) {
-      cache = new WeakHashMap();
-    }
 
-    synchronized (cache) {  // check cache
-      result = (SpanFilterResult) cache.get(reader);
-      if (result == null) {
-        result = filter.bitSpans(reader);
-        cache.put(reader, result);
-      }
+    final Object coreKey = reader.getFieldCacheKey();
+    final Object delCoreKey = reader.hasDeletions() ? reader.getDeletesCacheKey() : coreKey;
+
+    SpanFilterResult result = (SpanFilterResult) cache.get(reader, coreKey, delCoreKey);
+    if (result != null) {
+      hitCount++;
+      return result;
     }
+
+    missCount++;
+    result = filter.bitSpans(reader);
+
+    cache.put(coreKey, delCoreKey, result);
     return result;
   }
 

Modified: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingWrapperFilter.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingWrapperFilter.java
(original)
+++ lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/CachingWrapperFilter.java
Wed Jun  2 16:03:19 2010
@@ -17,13 +17,15 @@ package org.apache.lucene.search;
  * limitations under the License.
  */
 
+import java.io.Serializable;
+import java.io.IOException;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.util.DocIdBitSet;
 import org.apache.lucene.util.OpenBitSetDISI;
+import org.apache.lucene.util.Parameter;
 import java.util.BitSet;
 import java.util.WeakHashMap;
 import java.util.Map;
-import java.io.IOException;
 
 /**
  * Wraps another filter's result and caches it.  The purpose is to allow
@@ -33,30 +35,144 @@ public class CachingWrapperFilter extend
   protected Filter filter;
 
   /**
-   * A transient Filter cache.
+   * Expert: Specifies how new deletions against a reopened
+   * reader should be handled.
+   *
+   * <p>The default is IGNORE, which means the cache entry
+   * will be re-used for a given segment, even when that
+   * segment has been reopened due to changes in deletions.
+   * This is a big performance gain, especially with
+   * near-real-timer readers, since you don't hit a cache
+   * miss on every reopened reader for prior segments.</p>
+   *
+   * <p>However, in some cases this can cause invalid query
+   * results, allowing deleted documents to be returned.
+   * This only happens if the main query does not rule out
+   * deleted documents on its own, such as a toplevel
+   * ConstantScoreQuery.  To fix this, use RECACHE to
+   * re-create the cached filter (at a higher per-reopen
+   * cost, but at faster subsequent search performance), or
+   * use DYNAMIC to dynamically intersect deleted docs (fast
+   * reopen time but some hit to search performance).</p>
    */
-  protected transient Map cache;
+  public static final class DeletesMode extends Parameter implements Serializable {
+    private DeletesMode(String name) {
+      super(name);
+    }
+    public static DeletesMode IGNORE = new DeletesMode("IGNORE");
+    public static DeletesMode RECACHE = new DeletesMode("RECACHE");
+    public static DeletesMode DYNAMIC = new DeletesMode("DYNAMIC");
+  }
+
+  protected final FilterCache cache;
+
+  static abstract class FilterCache implements Serializable {
+
+    /**
+     * A transient Filter cache (package private because of test)
+     */
+    // NOTE: not final so that we can dynamically re-init
+    // after de-serialize
+    transient Map cache;
+
+    private final DeletesMode deletesMode;
+
+    public FilterCache(DeletesMode deletesMode) {
+      this.deletesMode = deletesMode;
+    }
+
+    public synchronized Object get(IndexReader reader, Object coreKey, Object delCoreKey)
throws IOException {
+      Object value;
+
+      if (cache == null) {
+        cache = new WeakHashMap();
+      }
+
+      if (deletesMode == DeletesMode.IGNORE) {
+        // key on core
+        value = cache.get(coreKey);
+      } else if (deletesMode == DeletesMode.RECACHE) {
+        // key on deletes, if any, else core
+        value = cache.get(delCoreKey);
+      } else {
+
+        assert deletesMode == DeletesMode.DYNAMIC;
+
+        // first try for exact match
+        value = cache.get(delCoreKey);
+
+        if (value == null) {
+          // now for core match, but dynamically AND NOT
+          // deletions
+          value = cache.get(coreKey);
+          if (value != null && reader.hasDeletions()) {
+            value = mergeDeletes(reader, value);
+          }
+        }
+      }
+
+      return value;
+    }
+
+    protected abstract Object mergeDeletes(IndexReader reader, Object value);
+
+    public synchronized void put(Object coreKey, Object delCoreKey, Object value) {
+      if (deletesMode == DeletesMode.IGNORE) {
+        cache.put(coreKey, value);
+      } else if (deletesMode == DeletesMode.RECACHE) {
+        cache.put(delCoreKey, value);
+      } else {
+        cache.put(coreKey, value);
+        cache.put(delCoreKey, value);
+      }
+    }
+  }
 
   /**
+   * New deletes are ignored by default, which gives higher
+   * cache hit rate on reopened readers.  Most of the time
+   * this is safe, because the filter will be AND'd with a
+   * Query that fully enforces deletions.  If instead you
+   * need this filter to always enforce deletions, pass
+   * either {@link DeletesMode#RECACHE} or {@link
+   * DeletesMode#DYNAMIC}.
    * @param filter Filter to cache results of
    */
   public CachingWrapperFilter(Filter filter) {
+    this(filter, DeletesMode.IGNORE);
+  }
+
+  /**
+   * Expert: by default, the cached filter will be shared
+   * across reopened segments that only had changes to their
+   * deletions.  
+   *
+   * @param filter Filter to cache results of
+   * @param deletesMode See {@link DeletesMode}
+   */
+  public CachingWrapperFilter(Filter filter, DeletesMode deletesMode) {
     this.filter = filter;
+    cache = new FilterCache(deletesMode) {
+      public Object mergeDeletes(final IndexReader r, final Object docIdSet) {
+        return new FilteredDocIdSet((DocIdSet) docIdSet) {
+          protected boolean match(int docID) {
+            return !r.isDeleted(docID);
+          }
+        };
+      }
+    };
   }
 
   /**
    * @deprecated Use {@link #getDocIdSet(IndexReader)} instead.
    */
   public BitSet bits(IndexReader reader) throws IOException {
-    if (cache == null) {
-      cache = new WeakHashMap();
-    }
 
-    Object cached = null;
-    synchronized (cache) {  // check cache
-      cached = cache.get(reader);
-    }
-	
+    final Object coreKey = reader.getFieldCacheKey();
+    final Object delCoreKey = reader.hasDeletions() ? reader.getDeletesCacheKey() : coreKey;
+
+    Object cached = cache.get(reader, coreKey, delCoreKey);
+
     if (cached != null) {
       if (cached instanceof BitSet) {
         return (BitSet) cached;
@@ -67,8 +183,8 @@ public class CachingWrapperFilter extend
 
     final BitSet bits = filter.bits(reader);
 
-    synchronized (cache) {  // update cache
-      cache.put(reader, bits);
+    if (bits != null) {
+      cache.put(coreKey, delCoreKey, bits);
     }
 
     return bits;
@@ -94,30 +210,31 @@ public class CachingWrapperFilter extend
       return (it == null) ? DocIdSet.EMPTY_DOCIDSET : new OpenBitSetDISI(it, reader.maxDoc());
     }
   }
-  
+
+  // for testing
+  int hitCount, missCount;
+
   public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
-    if (cache == null) {
-      cache = new WeakHashMap();
-    }
 
-    Object cached = null;
-    synchronized (cache) {  // check cache
-      cached = cache.get(reader);
-    }
+    final Object coreKey = reader.getFieldCacheKey();
+    final Object delCoreKey = reader.hasDeletions() ? reader.getDeletesCacheKey() : coreKey;
 
+    Object cached = cache.get(reader, coreKey, delCoreKey);
     if (cached != null) {
+      hitCount++;
       if (cached instanceof DocIdSet)
         return (DocIdSet) cached;
       else
         return new DocIdBitSet((BitSet) cached);
     }
 
+    missCount++;
+
+    // cache miss
     final DocIdSet docIdSet = docIdSetToCache(filter.getDocIdSet(reader), reader);
 
     if (docIdSet != null) {
-      synchronized (cache) {  // update cache
-        cache.put(reader, docIdSet);
-      }
+      cache.put(coreKey, delCoreKey, docIdSet);
     }
 
     return docIdSet;

Propchange: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/java/org/apache/lucene/search/MultiTermQueryWrapperFilter.java:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/java/org/apache/lucene/util/AttributeSource.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,5 +1,5 @@
 /lucene/dev/branches/branch_3x/lucene/src/java/org/apache/lucene/util/AttributeSource.java:946651
 /lucene/dev/trunk/lucene/src/java/org/apache/lucene/util/AttributeSource.java:929738,932398,935522,940730,946599,949976,949997
 /lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/util/AttributeSource.java:748824
-/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/util/AttributeSource.java:886275,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/java/branches/lucene_3_0/src/java/org/apache/lucene/util/AttributeSource.java:886275,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/java/org/apache/lucene/util/AttributeSource.java:821888,824125,826029,826385,830871,833095,833297,833886,834035,836155,881819,882672,883554,884870,886257,887347,887532,887670,889579,889866,890439,891189,891205,891363,894348,897672,908975,910034,910078,912407,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,5 +1,5 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:946651
 /lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:929738,932398,935522,940730,946599,949976,949997
 /lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:748824
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:886275,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:886275,889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/analysis/BaseTokenStreamTestCase.java:818920,821888,824125,826029,826385,830871,833095,833297,833886,834035,836155,881819,882672,883554,884870,887347,887532,887670,889579,889866,890439,891189,891205,891363,897672,908975,910034,910078,912407,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/analysis/TestISOLatin1AccentFilter.java:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestDateTools.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/document/TestDateTools.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/test/org/apache/lucene/document/TestDateTools.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/document/TestDateTools.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/test/org/apache/lucene/document/TestDateTools.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/document/TestDateTools.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/document/TestDateTools.java:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/document/TestNumberTools.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/document/TestNumberTools.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/test/org/apache/lucene/document/TestNumberTools.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/document/TestNumberTools.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/test/org/apache/lucene/document/TestNumberTools.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/document/TestNumberTools.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/document/TestNumberTools.java:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index:941394,946651
-/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index:940730,950458
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index:950301,950474
+/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index:940730,949288,950458
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index:950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/index:834035,836155,887670,889579,889866,890439,891205,891377,920270

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270

Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/CachingWrapperFilterHelper.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/CachingWrapperFilterHelper.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/CachingWrapperFilterHelper.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/CachingWrapperFilterHelper.java
Wed Jun  2 16:03:19 2010
@@ -18,10 +18,8 @@ package org.apache.lucene.search;
  */
 
 import java.io.IOException;
-import java.util.BitSet;
-import java.util.WeakHashMap;
 
-import junit.framework.TestCase;
+import junit.framework.Assert;
 
 import org.apache.lucene.index.IndexReader;
 
@@ -43,30 +41,18 @@ public class CachingWrapperFilterHelper 
     this.shouldHaveCache = shouldHaveCache;
   }
   
-  public DocIdSet getDocIdSet(IndexReader reader) throws IOException {
-    if (cache == null) {
-      cache = new WeakHashMap();
-    }
-    
-    synchronized (cache) {  // check cache
-      DocIdSet cached = (DocIdSet) cache.get(reader);
-      if (shouldHaveCache) {
-        TestCase.assertNotNull("Cache should have data ", cached);
-      } else {
-        TestCase.assertNull("Cache should be null " + cached , cached);
-      }
-      if (cached != null) {
-        return cached;
-      }
-    }
+  public synchronized DocIdSet getDocIdSet(IndexReader reader) throws IOException {
 
-    final DocIdSet bits = filter.getDocIdSet(reader);
+    final int saveMissCount = missCount;
+    DocIdSet docIdSet = super.getDocIdSet(reader);
 
-    synchronized (cache) {  // update cache
-      cache.put(reader, bits);
+    if (shouldHaveCache) {
+      Assert.assertEquals("Cache should have data ", saveMissCount, missCount);
+    } else {
+      Assert.assertTrue("Cache should be null " + docIdSet, missCount > saveMissCount);
     }
 
-    return bits;
+    return docIdSet;
   }
 
   public String toString() {

Modified: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java?rev=950612&r1=950611&r2=950612&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
(original)
+++ lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
Wed Jun  2 16:03:19 2010
@@ -20,12 +20,16 @@ package org.apache.lucene.search;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.lucene.util.OpenBitSet;
 import org.apache.lucene.util.OpenBitSetDISI;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.analysis.WhitespaceAnalyzer;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.analysis.KeywordAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.RAMDirectory;
+import org.apache.lucene.store.MockRAMDirectory;
 
 import java.io.IOException;
 import java.util.BitSet;
@@ -146,4 +150,123 @@ public class TestCachingWrapperFilter ex
 
     reader.close();
   }
+
+  public void testEnforceDeletions() throws Exception {
+    Directory dir = new MockRAMDirectory();
+    IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
+    IndexReader reader = writer.getReader();
+    IndexSearcher searcher = new IndexSearcher(reader);
+
+    // add a doc, refresh the reader, and check that its there
+    Document doc = new Document();
+    doc.add(new Field("id", "1", Field.Store.YES, Field.Index.NOT_ANALYZED));
+    writer.addDocument(doc);
+
+    reader = refreshReader(reader);
+    searcher = new IndexSearcher(reader);
+
+    TopDocs docs = searcher.search(new MatchAllDocsQuery(), 1);
+    assertEquals("Should find a hit...", 1, docs.totalHits);
+
+    final Filter startFilter = new QueryWrapperFilter(new TermQuery(new Term("id", "1")));
+
+    // ignore deletions
+    CachingWrapperFilter filter = new CachingWrapperFilter(startFilter, CachingWrapperFilter.DeletesMode.IGNORE);
+        
+    docs = searcher.search(new MatchAllDocsQuery(), filter, 1);
+    assertEquals("[query + filter] Should find a hit...", 1, docs.totalHits);
+    ConstantScoreQuery constantScore = new ConstantScoreQuery(filter);
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);
+
+    // now delete the doc, refresh the reader, and see that it's not there
+    writer.deleteDocuments(new Term("id", "1"));
+
+    reader = refreshReader(reader);
+    searcher = new IndexSearcher(reader);
+
+    docs = searcher.search(new MatchAllDocsQuery(), filter, 1);
+    assertEquals("[query + filter] Should *not* find a hit...", 0, docs.totalHits);
+
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);
+
+
+    // force cache to regenerate:
+    filter = new CachingWrapperFilter(startFilter, CachingWrapperFilter.DeletesMode.RECACHE);
+
+    writer.addDocument(doc);
+    reader = refreshReader(reader);
+    searcher = new IndexSearcher(reader);
+        
+    docs = searcher.search(new MatchAllDocsQuery(), filter, 1);
+    assertEquals("[query + filter] Should find a hit...", 1, docs.totalHits);
+
+    constantScore = new ConstantScoreQuery(filter);
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);
+
+    // make sure we get a cache hit when we reopen reader
+    // that had no change to deletions
+    IndexReader newReader = refreshReader(reader);
+    assertTrue(reader != newReader);
+    reader = newReader;
+    searcher = new IndexSearcher(reader);
+    int missCount = filter.missCount;
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);
+    assertEquals(missCount, filter.missCount);
+
+    // now delete the doc, refresh the reader, and see that it's not there
+    writer.deleteDocuments(new Term("id", "1"));
+
+    reader = refreshReader(reader);
+    searcher = new IndexSearcher(reader);
+
+    missCount = filter.missCount;
+    docs = searcher.search(new MatchAllDocsQuery(), filter, 1);
+    assertEquals(missCount+1, filter.missCount);
+    assertEquals("[query + filter] Should *not* find a hit...", 0, docs.totalHits);
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should *not* find a hit...", 0, docs.totalHits);
+
+
+    // apply deletions dynamically
+    filter = new CachingWrapperFilter(startFilter, CachingWrapperFilter.DeletesMode.DYNAMIC);
+
+    writer.addDocument(doc);
+    reader = refreshReader(reader);
+    searcher = new IndexSearcher(reader);
+        
+    docs = searcher.search(new MatchAllDocsQuery(), filter, 1);
+    assertEquals("[query + filter] Should find a hit...", 1, docs.totalHits);
+    constantScore = new ConstantScoreQuery(filter);
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should find a hit...", 1, docs.totalHits);
+
+    // now delete the doc, refresh the reader, and see that it's not there
+    writer.deleteDocuments(new Term("id", "1"));
+
+    reader = refreshReader(reader);
+    searcher = new IndexSearcher(reader);
+
+    docs = searcher.search(new MatchAllDocsQuery(), filter, 1);
+    assertEquals("[query + filter] Should *not* find a hit...", 0, docs.totalHits);
+
+    missCount = filter.missCount;
+    docs = searcher.search(constantScore, 1);
+    assertEquals("[just filter] Should *not* find a hit...", 0, docs.totalHits);
+
+    // doesn't count as a miss
+    assertEquals(missCount, filter.missCount);
+  }
+
+  private static IndexReader refreshReader(IndexReader reader) throws IOException {
+    IndexReader oldReader = reader;
+    reader = reader.reopen();
+    if (reader != oldReader) {
+      oldReader.close();
+    }
+    return reader;
+  }
 }

Propchange: lucene/java/branches/lucene_2_9/src/test/org/apache/lucene/util/TestAttributeSource.java
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  2 16:03:19 2010
@@ -1,4 +1,4 @@
 /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java:941394,946651,948430
-/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949976,949997,950458
-/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/util/TestAttributeSource.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474
+/lucene/dev/trunk/lucene/src/test/org/apache/lucene/util/TestAttributeSource.java:929738,932398,935522,938989,939611,939649,940730,946599,948082,948429,949288,949976,949997,950458
+/lucene/java/branches/lucene_3_0/src/test/org/apache/lucene/util/TestAttributeSource.java:889688,891211,899639,900212,908479,909401,912383,915404,940993,948090,948432,950033,950301,950474,950580
 /lucene/java/trunk/src/test/org/apache/lucene/util/TestAttributeSource.java:821888,834035,836155,881819,886257,887347,887532,887670,889431-889432,889579,889866,890439,891189,891205,891209,891363,891377,897672,899627,900196,908477,908975,909398,910034,910078,912407,915399,919060,920270



Mime
View raw message