LUCENE-6416: BooleanQuery.extractTerms now only extracts terms from scoring clauses.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1673120 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrien Grand 2015-04-13 07:01:29 +00:00
parent 9b060c407e
commit 8fe8e84278
3 changed files with 21 additions and 1 deletions

View File

@ -85,6 +85,9 @@ Bug Fixes
* LUCENE-6415: TermsQuery.extractTerms is a no-op (used to throw an
UnsupportedOperationException). (Adrien Grand)
* LUCENE-6416: BooleanQuery.extractTerms now only extracts terms from scoring
clauses. (Adrien Grand)
API Changes
* LUCENE-6377: SearcherFactory#newSearcher now accepts the previous reader

View File

@ -237,7 +237,7 @@ public class BooleanQuery extends Query implements Iterable<BooleanClause> {
@Override
public void extractTerms(Set<Term> terms) {
for (BooleanClause clause : clauses) {
if (clause.isProhibited() == false) {
if (clause.isScoring()) {
clause.getQuery().extractTerms(terms);
}
}

View File

@ -21,7 +21,9 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@ -755,4 +757,19 @@ public class TestBooleanQuery extends LuceneTestCase {
bq.add(new TermQuery(new Term("field", "d")), Occur.FILTER);
assertEquals("a +b -c #d", bq.toString("field"));
}
public void testExtractTerms() {
Term a = new Term("f", "a");
Term b = new Term("f", "b");
Term c = new Term("f", "c");
Term d = new Term("f", "d");
BooleanQuery bq = new BooleanQuery();
bq.add(new TermQuery(a), Occur.SHOULD);
bq.add(new TermQuery(b), Occur.MUST);
bq.add(new TermQuery(c), Occur.FILTER);
bq.add(new TermQuery(d), Occur.MUST_NOT);
Set<Term> terms = new HashSet<>();
bq.extractTerms(terms);
assertEquals(new HashSet<>(Arrays.asList(a, b)), terms);
}
}