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.
Query rules retriever (elastic#114855)
- Loading branch information
Showing
11 changed files
with
1,060 additions
and
1 deletion.
There are no files selected for viewing
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,5 @@ | ||
pr: 114855 | ||
summary: Add query rules retriever | ||
area: Relevance | ||
type: enhancement | ||
issues: [ ] |
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
142 changes: 142 additions & 0 deletions
142
server/src/main/java/org/elasticsearch/search/retriever/RetrieverBuilderWrapper.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,142 @@ | ||
/* | ||
* 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.search.retriever; | ||
|
||
import org.elasticsearch.action.ActionRequestValidationException; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.QueryRewriteContext; | ||
import org.elasticsearch.search.builder.SearchSourceBuilder; | ||
import org.elasticsearch.search.rank.RankDoc; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
/** | ||
* A wrapper that can be used to modify the behaviour of an existing {@link RetrieverBuilder}. | ||
*/ | ||
public abstract class RetrieverBuilderWrapper<T extends RetrieverBuilder> extends RetrieverBuilder { | ||
protected final RetrieverBuilder in; | ||
|
||
protected RetrieverBuilderWrapper(RetrieverBuilder in) { | ||
this.in = in; | ||
} | ||
|
||
protected abstract T clone(RetrieverBuilder sub); | ||
|
||
@Override | ||
public RetrieverBuilder rewrite(QueryRewriteContext ctx) throws IOException { | ||
var inRewrite = in.rewrite(ctx); | ||
if (inRewrite != in) { | ||
return clone(inRewrite); | ||
} | ||
return this; | ||
} | ||
|
||
@Override | ||
public QueryBuilder topDocsQuery() { | ||
return in.topDocsQuery(); | ||
} | ||
|
||
@Override | ||
public RetrieverBuilder minScore(Float minScore) { | ||
return in.minScore(minScore); | ||
} | ||
|
||
@Override | ||
public List<QueryBuilder> getPreFilterQueryBuilders() { | ||
return in.preFilterQueryBuilders; | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate( | ||
SearchSourceBuilder source, | ||
ActionRequestValidationException validationException, | ||
boolean isScroll, | ||
boolean allowPartialSearchResults | ||
) { | ||
return in.validate(source, validationException, isScroll, allowPartialSearchResults); | ||
} | ||
|
||
@Override | ||
public RetrieverBuilder retrieverName(String retrieverName) { | ||
return in.retrieverName(retrieverName); | ||
} | ||
|
||
@Override | ||
public void setRankDocs(RankDoc[] rankDocs) { | ||
in.setRankDocs(rankDocs); | ||
} | ||
|
||
@Override | ||
public RankDoc[] getRankDocs() { | ||
return in.getRankDocs(); | ||
} | ||
|
||
@Override | ||
public boolean isCompound() { | ||
return in.isCompound(); | ||
} | ||
|
||
@Override | ||
public QueryBuilder explainQuery() { | ||
return in.explainQuery(); | ||
} | ||
|
||
@Override | ||
public Float minScore() { | ||
return in.minScore(); | ||
} | ||
|
||
@Override | ||
public boolean isFragment() { | ||
return in.isFragment(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return in.toString(); | ||
} | ||
|
||
@Override | ||
public String retrieverName() { | ||
return in.retrieverName(); | ||
} | ||
|
||
@Override | ||
public void extractToSearchSourceBuilder(SearchSourceBuilder searchSourceBuilder, boolean compoundUsed) { | ||
in.extractToSearchSourceBuilder(searchSourceBuilder, compoundUsed); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return in.getName(); | ||
} | ||
|
||
@Override | ||
protected void doToXContent(XContentBuilder builder, Params params) throws IOException { | ||
in.doToXContent(builder, params); | ||
} | ||
|
||
@Override | ||
protected boolean doEquals(Object o) { | ||
// Handle the edge case where we need to unwrap the incoming retriever | ||
if (o instanceof RetrieverBuilderWrapper<?> wrapper) { | ||
return in.doEquals(wrapper.in); | ||
} else { | ||
return in.doEquals(o); | ||
} | ||
} | ||
|
||
@Override | ||
protected int doHashCode() { | ||
return in.doHashCode(); | ||
} | ||
} |
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
Oops, something went wrong.