forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove intercept flag from MatchQueryBuilder and replace with wrapper
- Loading branch information
Showing
3 changed files
with
109 additions
and
49 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
server/src/main/java/org/elasticsearch/index/query/InterceptedQueryBuilderWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.index.query; | ||
|
||
import org.apache.lucene.search.Query; | ||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Wrapper for queries that have been intercepted using the {@link QueryRewriteInterceptor} that may need to | ||
* break out of the rewrite phase. | ||
* @param <T> | ||
*/ | ||
public class InterceptedQueryBuilderWrapper<T extends AbstractQueryBuilder<T>> extends AbstractQueryBuilder<T> { | ||
|
||
protected final T queryBuilder; | ||
|
||
public InterceptedQueryBuilderWrapper(T queryBuilder) { | ||
super(); | ||
this.queryBuilder = queryBuilder; | ||
} | ||
|
||
@Override | ||
protected void doWriteTo(StreamOutput out) throws IOException { | ||
queryBuilder.writeTo(out); | ||
} | ||
|
||
@Override | ||
protected void doXContent(XContentBuilder builder, Params params) throws IOException { | ||
queryBuilder.toXContent(builder, params); | ||
} | ||
|
||
@Override | ||
protected Query doToQuery(SearchExecutionContext context) throws IOException { | ||
return queryBuilder.doToQuery(context); | ||
} | ||
|
||
@Override | ||
protected boolean doEquals(T other) { | ||
// Handle the edge case where we need to unwrap the incoming query builder | ||
if (other instanceof InterceptedQueryBuilderWrapper) { | ||
@SuppressWarnings("unchecked") | ||
InterceptedQueryBuilderWrapper<T> wrapper = (InterceptedQueryBuilderWrapper<T>) other; | ||
return queryBuilder.doEquals(wrapper.queryBuilder); | ||
} else { | ||
return queryBuilder.doEquals(other); | ||
} | ||
} | ||
|
||
@Override | ||
protected int doHashCode() { | ||
return queryBuilder.doHashCode(); | ||
} | ||
|
||
@Override | ||
public String getWriteableName() { | ||
return queryBuilder.getWriteableName(); | ||
} | ||
|
||
@Override | ||
public TransportVersion getMinimalSupportedVersion() { | ||
return queryBuilder.getMinimalSupportedVersion(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters