Apache Lucene open-source search software
test for FilteredQuery within BooleanQuery
Erik Hatcher0e28bac0d8df
diff --git a/src/test/org/apache/lucene/search/SingleDocTestFilter.java b/src/test/org/apache/lucene/search/SingleDocTestFilter.javanew file mode 100644index 00000000000..646b3bb5325--- /dev/null+++ b/src/test/org/apache/lucene/search/SingleDocTestFilter.java@@ -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;+ }+}diff --git a/src/test/org/apache/lucene/search/TestFilteredQuery.java b/src/test/org/apache/lucene/search/TestFilteredQuery.javaindex 411782f5907..84a1f6e5f89 100644--- a/src/test/org/apache/lucene/search/TestFilteredQuery.java+++ b/src/test/org/apache/lucene/search/TestFilteredQuery.java@@ -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());+ }}