LUCENE-1504 -- SerialChainFilter should use DocSet API

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@732031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2009-01-06 18:13:06 +00:00
parent 873fbbc1f1
commit 43609e891d
1 changed files with 209 additions and 199 deletions

View File

@ -22,18 +22,20 @@ import java.util.BitSet;
import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter; import org.apache.lucene.search.Filter;
import org.apache.lucene.util.DocIdBitSet;
/** /**
* *
* Provide a serial chain filter, passing the bitset in with the * Provide a serial chain filter, passing the bitset in with the
* index reader to each of the filters in an ordered fashion. * index reader to each of the filters in an ordered fashion.
* *
* Based off chain filter, but will some improvements to allow a narrowed down * Based off chain filter, but with some improvements to allow a narrowed down
* filtering. Traditional filter required iteration through an IndexReader. * filtering. Traditional filter required iteration through an IndexReader.
* *
* By implementing the ISerialChainFilter class, you can create a bits(IndexReader reader, BitSet bits) * By implementing the ISerialChainFilter class, you can create a bits(IndexReader reader, BitSet bits)
* @see org.apache.lucene.spatial.ISerialChainFilter * @see org.apache.lucene.search.ISerialChainFilter
* *
*/ */
public class SerialChainFilter extends Filter { public class SerialChainFilter extends Filter {
@ -65,7 +67,16 @@ public class SerialChainFilter extends Filter {
* @see org.apache.lucene.search.Filter#bits(org.apache.lucene.index.IndexReader) * @see org.apache.lucene.search.Filter#bits(org.apache.lucene.index.IndexReader)
*/ */
@Override @Override
public BitSet bits(IndexReader reader) throws CorruptIndexException, IOException { public BitSet bits(IndexReader reader) throws IOException {
return ((DocIdBitSet)getDocIdSet(reader)).getBitSet();
}
/* (non-Javadoc)
* @see org.apache.lucene.search.Filter#getDocIdSet(org.apache.lucene.index.IndexReader)
*/
@Override
public DocIdSet getDocIdSet(IndexReader reader) throws CorruptIndexException, IOException {
BitSet bits = new BitSet(reader.maxDoc()); BitSet bits = new BitSet(reader.maxDoc());
int chainSize = chain.length; int chainSize = chain.length;
@ -77,7 +88,7 @@ public class SerialChainFilter extends Filter {
*/ */
if (actionType[i] == AND){ if (actionType[i] == AND){
try { try {
bits = (BitSet) chain[i].bits(reader).clone(); bits = (BitSet) ((DocIdBitSet)chain[i].getDocIdSet(reader)).getBitSet().clone();
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -114,15 +125,14 @@ public class SerialChainFilter extends Filter {
} }
break; break;
case (AND): case (AND):
bits.and(chain[i].bits(reader)); bits.and(((DocIdBitSet)chain[i].getDocIdSet(reader)).getBitSet());
break; break;
case (OR): case (OR):
bits.and(chain[i].bits(reader)); bits.or(((DocIdBitSet)chain[i].getDocIdSet(reader)).getBitSet());
break; break;
} }
} }
return bits; return new DocIdBitSet(bits);
} }
/** /**