lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r745800 - in /lucene/java/branches/lucene_2_4: ./ CHANGES.txt src/java/org/apache/lucene/search/CachingWrapperFilter.java src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
Date Thu, 19 Feb 2009 10:03:20 GMT
Author: mikemccand
Date: Thu Feb 19 10:03:20 2009
New Revision: 745800

URL: http://svn.apache.org/viewvc?rev=745800&view=rev
Log:
LUCENE-1459: fix CachingWrapperFilter to not throw exception if both bits() and getDocIdSet()
are called

Modified:
    lucene/java/branches/lucene_2_4/   (props changed)
    lucene/java/branches/lucene_2_4/CHANGES.txt
    lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/search/CachingWrapperFilter.java
    lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java

Propchange: lucene/java/branches/lucene_2_4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb 19 10:03:20 2009
@@ -1 +1 @@
-/lucene/java/trunk:708549,709456,712233,718540,723149
+/lucene/java/trunk:708549,709456,712233,718540,719716,723149

Modified: lucene/java/branches/lucene_2_4/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/CHANGES.txt?rev=745800&r1=745799&r2=745800&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/CHANGES.txt (original)
+++ lucene/java/branches/lucene_2_4/CHANGES.txt Thu Feb 19 10:03:20 2009
@@ -34,6 +34,10 @@
 7. LUCENE-1457: Fix possible overflow bugs during binary
    searches. (Mark Miller via Mike McCandless)
 
+8. LUCENE-1459: Fix CachingWrapperFilter to not throw exception if
+   both bits() and getDocIdSet() methods are called. (Matt Jones via
+   Mike McCandless)
+
 
 ======================= Release 2.4.0 2008-10-06 =======================
 

Modified: lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/search/CachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/search/CachingWrapperFilter.java?rev=745800&r1=745799&r2=745800&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/search/CachingWrapperFilter.java
(original)
+++ lucene/java/branches/lucene_2_4/src/java/org/apache/lucene/search/CachingWrapperFilter.java
Thu Feb 19 10:03:20 2009
@@ -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/branches/lucene_2_4/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java?rev=745800&r1=745799&r2=745800&view=diff
==============================================================================
--- lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
(original)
+++ lucene/java/branches/lucene_2_4/src/test/org/apache/lucene/search/TestCachingWrapperFilter.java
Thu Feb 19 10:03:20 2009
@@ -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