mirror of https://github.com/apache/lucene.git
LUCENE-6839: Make SpanOrQuery immutable.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1708826 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c855dd5a33
commit
15016f17e8
|
@ -111,6 +111,9 @@ API Changes
|
|||
order to let Lucene know that a Query should be used for filtering but not
|
||||
scoring.
|
||||
|
||||
* LUCENE-6939: SpanOrQuery.addClause is now deprecated, clauses should all be
|
||||
provided at construction time. (Paul Elschot via Adrien Grand)
|
||||
|
||||
Optimizations
|
||||
|
||||
* LUCENE-6708: TopFieldCollector does not compute the score several times on the
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.apache.lucene.search.TopTermsRewrite;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Wraps any {@link MultiTermQuery} as a {@link SpanQuery},
|
||||
|
@ -156,14 +158,14 @@ public class SpanMultiTermQueryWrapper<Q extends MultiTermQuery> extends SpanQue
|
|||
* @see #setRewriteMethod
|
||||
*/
|
||||
public final static SpanRewriteMethod SCORING_SPAN_QUERY_REWRITE = new SpanRewriteMethod() {
|
||||
private final ScoringRewrite<SpanOrQuery> delegate = new ScoringRewrite<SpanOrQuery>() {
|
||||
private final ScoringRewrite<List<SpanQuery>> delegate = new ScoringRewrite<List<SpanQuery>>() {
|
||||
@Override
|
||||
protected SpanOrQuery getTopLevelBuilder() {
|
||||
return new SpanOrQuery();
|
||||
protected List<SpanQuery> getTopLevelBuilder() {
|
||||
return new ArrayList<SpanQuery>();
|
||||
}
|
||||
|
||||
protected Query build(SpanOrQuery builder) {
|
||||
return builder;
|
||||
protected Query build(List<SpanQuery> builder) {
|
||||
return new SpanOrQuery(builder.toArray(new SpanQuery[builder.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -172,9 +174,9 @@ public class SpanMultiTermQueryWrapper<Q extends MultiTermQuery> extends SpanQue
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void addClause(SpanOrQuery topLevel, Term term, int docCount, float boost, TermContext states) {
|
||||
protected void addClause(List<SpanQuery> topLevel, Term term, int docCount, float boost, TermContext states) {
|
||||
final SpanTermQuery q = new SpanTermQuery(term, states);
|
||||
topLevel.addClause(q);
|
||||
topLevel.add(q);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -196,33 +198,33 @@ public class SpanMultiTermQueryWrapper<Q extends MultiTermQuery> extends SpanQue
|
|||
* @see #setRewriteMethod
|
||||
*/
|
||||
public static final class TopTermsSpanBooleanQueryRewrite extends SpanRewriteMethod {
|
||||
private final TopTermsRewrite<SpanOrQuery> delegate;
|
||||
private final TopTermsRewrite<List<SpanQuery>> delegate;
|
||||
|
||||
/**
|
||||
* Create a TopTermsSpanBooleanQueryRewrite for
|
||||
* at most <code>size</code> terms.
|
||||
*/
|
||||
public TopTermsSpanBooleanQueryRewrite(int size) {
|
||||
delegate = new TopTermsRewrite<SpanOrQuery>(size) {
|
||||
delegate = new TopTermsRewrite<List<SpanQuery>>(size) {
|
||||
@Override
|
||||
protected int getMaxSize() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SpanOrQuery getTopLevelBuilder() {
|
||||
return new SpanOrQuery();
|
||||
protected List<SpanQuery> getTopLevelBuilder() {
|
||||
return new ArrayList<SpanQuery>();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Query build(SpanOrQuery builder) {
|
||||
return builder;
|
||||
protected Query build(List<SpanQuery> builder) {
|
||||
return new SpanOrQuery(builder.toArray(new SpanQuery[builder.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addClause(SpanOrQuery topLevel, Term term, int docFreq, float boost, TermContext states) {
|
||||
protected void addClause(List<SpanQuery> topLevel, Term term, int docFreq, float boost, TermContext states) {
|
||||
final SpanTermQuery q = new SpanTermQuery(term, states);
|
||||
topLevel.addClause(q);
|
||||
topLevel.add(q);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ public final class SpanOrQuery extends SpanQuery {
|
|||
}
|
||||
|
||||
/** Adds a clause to this query */
|
||||
public final void addClause(SpanQuery clause) {
|
||||
private final void addClause(SpanQuery clause) {
|
||||
if (field == null) {
|
||||
field = clause.getField();
|
||||
} else if (clause.getField() != null && !clause.getField().equals(field)) {
|
||||
|
|
Loading…
Reference in New Issue