test for FilteredQuery within BooleanQuery

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@383343 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2006-03-05 15:44:44 +00:00
parent ec8db2aae0
commit 0e28bac0d8
2 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1,36 @@
package org.apache.lucene.search;
/**
* Copyright 2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.lucene.index.IndexReader;
import java.util.BitSet;
import java.io.IOException;
public class SingleDocTestFilter extends Filter {
private int doc;
public SingleDocTestFilter(int doc) {
this.doc = doc;
}
public BitSet bits(IndexReader reader) throws IOException {
BitSet bits = new BitSet(reader.maxDoc());
bits.set(doc);
return bits;
}
}

View File

@ -1,7 +1,7 @@
package org.apache.lucene.search;
/**
* Copyright 2004 The Apache Software Foundation
* Copyright 2004,2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -126,5 +126,19 @@ extends TestCase {
assertEquals(2, hits.length());
}
public void testBoolean() throws Exception {
BooleanQuery bq = new BooleanQuery();
Query query = new FilteredQuery(new MatchAllDocsQuery(),
new SingleDocTestFilter(0));
bq.add(query, BooleanClause.Occur.MUST);
query = new FilteredQuery(new MatchAllDocsQuery(),
new SingleDocTestFilter(1));
bq.add(query, BooleanClause.Occur.MUST);
Hits hits = searcher.search(bq);
System.out.println(hits.id(0));
System.out.println(hits.id(1));
assertEquals(0, hits.length());
}
}