LUCENE-749: ChainedFilter behavior fixed when logic of first filter is ANDNOT.

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@607606 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Doron Cohen 2007-12-30 22:47:59 +00:00
parent f4639c0ab0
commit ece8361ab5
3 changed files with 34 additions and 0 deletions

View File

@ -207,6 +207,9 @@ Bug fixes
this flag to true fixes the problem. This flag is a temporary fix and is already
marked as being deprecated. 3.x will implement the correct approach. (Shai Erera via Grant Ingersoll)
28. LUCENE-749: ChainedFilter behavior fixed when logic of
first filter is ANDNOT. (Antonio Bruno via Doron Cohen)
New features

View File

@ -177,6 +177,12 @@ public class ChainedFilter extends Filter
result = (BitSet) chain[i].bits(reader).clone();
++i;
}
else if (logic == ANDNOT)
{
result = (BitSet) chain[i].bits(reader).clone();
result.flip(0,reader.maxDoc());
++i;
}
else
{
result = new BitSet(reader.maxDoc());
@ -212,6 +218,12 @@ public class ChainedFilter extends Filter
result = (BitSet) chain[i].bits(reader).clone();
++i;
}
else if (logic[0] == ANDNOT)
{
result = (BitSet) chain[i].bits(reader).clone();
result.flip(0,reader.maxDoc());
++i;
}
else
{
result = new BitSet(reader.maxDoc());

View File

@ -90,6 +90,16 @@ public class ChainedFilterTest extends TestCase {
chain = new ChainedFilter(new Filter[] {bobFilter});
hits = searcher.search(query, chain);
assertEquals(MAX / 2, hits.length());
chain = new ChainedFilter(new Filter[] {bobFilter}, new int[] {ChainedFilter.AND});
hits = searcher.search(query, chain);
assertEquals(MAX / 2, hits.length());
assertEquals("bob", hits.doc(0).get("owner"));
chain = new ChainedFilter(new Filter[] {bobFilter}, new int[] {ChainedFilter.ANDNOT});
hits = searcher.search(query, chain);
assertEquals(MAX / 2, hits.length());
assertEquals("sue", hits.doc(0).get("owner"));
}
public void testOR() throws Exception {
@ -127,6 +137,15 @@ public class ChainedFilterTest extends TestCase {
assertEquals("ANDNOT matches just bob",
MAX / 2, hits.length());
assertEquals("bob", hits.doc(0).get("owner"));
chain = new ChainedFilter(
new Filter[]{bobFilter, bobFilter},
new int[] {ChainedFilter.ANDNOT, ChainedFilter.ANDNOT});
hits = searcher.search(query, chain);
assertEquals("ANDNOT bob ANDNOT bob matches all sues",
MAX / 2, hits.length());
assertEquals("sue", hits.doc(0).get("owner"));
}
private Date parseDate(String s) throws ParseException {