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
This commit is contained in:
Mark Harwood 2007-01-24 22:19:05 +00:00
parent ec0dc7b8f6
commit 9251a63e01
1 changed files with 14 additions and 4 deletions

View File

@ -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());
}
}
}
}