lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mharw...@apache.org
Subject svn commit: r499592 - /lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java
Date Wed, 24 Jan 2007 22:19:10 GMT
Author: mharwood
Date: Wed Jan 24 14:19:05 2007
New Revision: 499592

URL: http://svn.apache.org/viewvc?view=rev&rev=499592
Log:
Fixed bug when BooleanFilter class is used in conjunction with cached filters - the anding
of filters' bitsets was changing the original rather than taking a copy of the contents. Changed
to use BitSet.clone before performing any destructive operation

Modified:
    lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java

Modified: lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java?view=diff&rev=499592&r1=499591&r2=499592
==============================================================================
--- lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java
(original)
+++ lucene/java/trunk/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java
Wed Jan 24 14:19:05 2007
@@ -41,9 +41,10 @@
 		if (shouldFilters!=null)
 		{
 			returnBits = ((Filter)shouldFilters.get(0)).bits(reader);
+//			avoid changing the original bitset - it may be cached
+			returnBits=(BitSet) returnBits.clone(); 
 			if (shouldFilters.size() > 1)
 			{
-				
 				for (int i = 1; i < shouldFilters.size(); i++)
 				{
 					returnBits.or(((Filter)shouldFilters.get(i)).bits(reader));
@@ -59,7 +60,7 @@
 				BitSet notBits=((Filter)notFilters.get(i)).bits(reader);
 				if(returnBits==null)
 				{
-					returnBits=notBits;
+					returnBits=(BitSet) notBits.clone();					
 					returnBits.flip(0,reader.maxDoc());
 				}
 				else
@@ -77,7 +78,16 @@
 				BitSet mustBits=((Filter)mustFilters.get(i)).bits(reader);
 				if(returnBits==null)
 				{
-					returnBits=mustBits;
+					if(mustFilters.size()==1)
+					{
+						returnBits=mustBits;
+						
+					}
+					else
+					{
+						//don't mangle the bitset
+						returnBits=(BitSet) mustBits.clone();						
+					}
 				}
 				else
 				{
@@ -124,4 +134,4 @@
 			notFilters.add(filterClause.getFilter());
 		}
 	}
-}
+}
\ No newline at end of file



Mime
View raw message