ChainedFilterpublic class ChainedFilter extends Filter
Allows multiple {@link Filter}s to be chained.
Logical operations such as NOT and XOR
are applied between filters. One operation can be used
for all filters, or a specific operation can be declared
for each filter.
Order in which filters are called depends on
the position of the filter in the chain. It's probably
more efficient to place the most restrictive filters
/least computationally-intensive filters first.
|
Fields Summary |
---|
public static final int | OR{@link BitSet#or}. | public static final int | AND{@link BitSet#and}. | public static final int | ANDNOT{@link BitSet#andNot}. | public static final int | XOR{@link BitSet#xor}. | public static int | DEFAULTLogical operation when none is declared. Defaults to
{@link BitSet#or}. | private Filter[] | chainThe filter chain | private int[] | logicArray | private int | logic |
Constructors Summary |
---|
public ChainedFilter(Filter[] chain)Ctor.
this.chain = chain;
| public ChainedFilter(Filter[] chain, int[] logicArray)Ctor.
this.chain = chain;
this.logicArray = logicArray;
| public ChainedFilter(Filter[] chain, int logic)Ctor.
this.chain = chain;
this.logic = logic;
|
Methods Summary |
---|
public java.util.BitSet | bits(org.apache.lucene.index.IndexReader reader){@link Filter#bits}.
if (logic != -1)
return bits(reader, logic);
else if (logicArray != null)
return bits(reader, logicArray);
else
return bits(reader, DEFAULT);
| private java.util.BitSet | bits(org.apache.lucene.index.IndexReader reader, int logic)Delegates to each filter in the chain.
BitSet result;
int i = 0;
/**
* First AND operation takes place against a completely false
* bitset and will always return zero results. Thanks to
* Daniel Armbrust for pointing this out and suggesting workaround.
*/
if (logic == AND)
{
result = (BitSet) chain[i].bits(reader).clone();
++i;
}
else
{
result = new BitSet(reader.maxDoc());
}
for (; i < chain.length; i++)
{
doChain(result, reader, logic, chain[i]);
}
return result;
| private java.util.BitSet | bits(org.apache.lucene.index.IndexReader reader, int[] logic)Delegates to each filter in the chain.
if (logic.length != chain.length)
throw new IllegalArgumentException("Invalid number of elements in logic array");
BitSet result;
int i = 0;
/**
* First AND operation takes place against a completely false
* bitset and will always return zero results. Thanks to
* Daniel Armbrust for pointing this out and suggesting workaround.
*/
if (logic[0] == AND)
{
result = (BitSet) chain[i].bits(reader).clone();
++i;
}
else
{
result = new BitSet(reader.maxDoc());
}
for (; i < chain.length; i++)
{
doChain(result, reader, logic[i], chain[i]);
}
return result;
| private void | doChain(java.util.BitSet result, org.apache.lucene.index.IndexReader reader, int logic, org.apache.lucene.search.Filter filter)
switch (logic)
{
case OR:
result.or(filter.bits(reader));
break;
case AND:
result.and(filter.bits(reader));
break;
case ANDNOT:
result.andNot(filter.bits(reader));
break;
case XOR:
result.xor(filter.bits(reader));
break;
default:
doChain(result, reader, DEFAULT, filter);
break;
}
| public java.lang.String | toString()
StringBuffer sb = new StringBuffer();
sb.append("ChainedFilter: [");
for (int i = 0; i < chain.length; i++)
{
sb.append(chain[i]);
sb.append(' ");
}
sb.append(']");
return sb.toString();
|
|