mirror of https://github.com/apache/lucene.git
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:
parent
f4639c0ab0
commit
ece8361ab5
|
@ -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
|
||||
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue