From 9251a63e01293f39243cd3fc7af3d22fbb9bdad0 Mon Sep 17 00:00:00 2001 From: Mark Harwood Date: Wed, 24 Jan 2007 22:19:05 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@499592 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/search/BooleanFilter.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 fe213fa5201..6f3c838b11e 100644 --- a/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java +++ b/contrib/queries/src/java/org/apache/lucene/search/BooleanFilter.java @@ -41,9 +41,10 @@ public class BooleanFilter extends Filter 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 @@ public class BooleanFilter extends Filter 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 @@ public class BooleanFilter extends Filter 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 @@ public class BooleanFilter extends Filter notFilters.add(filterClause.getFilter()); } } -} +} \ No newline at end of file