lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r719716 - in /lucene/java/trunk/src: java/org/apache/lucene/search/CachingWrapperFilter.java test/org/apache/lucene/search/TestCachingWrapperFilter.java
Date Fri, 21 Nov 2008 21:17:06 GMT
Author: mikemccand
Date: Fri Nov 21 13:17:06 2008
New Revision: 719716

URL: http://svn.apache.org/viewvc?rev=719716&view=rev
Log:
LUCENE-1459: fix CachingWrapperFilter to do the right thing if the wrong type of bitset is
in its cache

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/CachingWrapperFilter.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/CachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/CachingWrapperFilter.java?rev=719716&r1=719715&r2=719716&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/CachingWrapperFilter.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/CachingWrapperFilter.java Fri Nov
21 13:17:06 2008
@@ -18,6 +18,7 @@
  */
 
 import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.util.DocIdBitSet;
 import java.util.BitSet;
 import java.util.WeakHashMap;
 import java.util.Map;
@@ -51,11 +52,17 @@
       cache = new WeakHashMap();
     }
 
+    Object cached = null;
     synchronized (cache) {  // check cache
-      BitSet cached = (BitSet) cache.get(reader);
-      if (cached != null) {
-        return cached;
-      }
+      cached = cache.get(reader);
+    }
+	
+    if (cached != null) {
+      if (cached instanceof BitSet) {
+        return (BitSet) cached;
+      } else if (cached instanceof DocIdBitSet)
+        return ((DocIdBitSet) cached).getBitSet();
+      // It would be nice to handle the DocIdSet case, but that's not really possible
     }
 
     final BitSet bits = filter.bits(reader);
@@ -72,11 +79,16 @@
       cache = new WeakHashMap();
     }
 
+    Object cached = null;
     synchronized (cache) {  // check cache
-      DocIdSet cached = (DocIdSet) cache.get(reader);
-      if (cached != null) {
-        return cached;
-      }
+      cached = cache.get(reader);
+    }
+
+    if (cached != null) {
+      if (cached instanceof DocIdSet)
+        return (DocIdSet) cached;
+      else
+        return new DocIdBitSet((BitSet) cached);
     }
 
     final DocIdSet docIdSet = filter.getDocIdSet(reader);

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java?rev=719716&r1=719715&r2=719716&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java Fri
Nov 21 13:17:06 2008
@@ -39,11 +39,15 @@
     cacher.getDocIdSet(reader);
     assertTrue("first time", filter.wasCalled());
 
+    // make sure no exception if cache is holding the wrong bitset
+    cacher.bits(reader);
+    cacher.getDocIdSet(reader);
+
     // second time, nested filter should not be called
     filter.clear();
     cacher.getDocIdSet(reader);
     assertFalse("second time", filter.wasCalled());
 
     reader.close();
- }
+  }
 }



Mime
View raw message