mirror of https://github.com/apache/lucene.git
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:
parent
ec8db2aae0
commit
0e28bac0d8
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package org.apache.lucene.search;
|
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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -126,5 +126,19 @@ extends TestCase {
|
||||||
assertEquals(2, hits.length());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue