Skip to content

Commit 5717076

Browse files
committed
Added javadocs for MultiFieldsInnerRetrieverUtils
1 parent 030968a commit 5717076

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

x-pack/plugin/rank-rrf/src/main/java/org/elasticsearch/xpack/rank/MultiFieldsInnerRetrieverUtils.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.elasticsearch.search.retriever.CompoundRetrieverBuilder;
2020
import org.elasticsearch.search.retriever.RetrieverBuilder;
2121
import org.elasticsearch.search.retriever.StandardRetrieverBuilder;
22+
import org.elasticsearch.xpack.rank.linear.LinearRetrieverBuilder;
2223

2324
import java.util.ArrayList;
2425
import java.util.Collection;
@@ -32,11 +33,27 @@
3233
import static org.elasticsearch.action.ValidateActions.addValidationError;
3334
import static org.elasticsearch.index.IndexSettings.DEFAULT_FIELD_SETTING;
3435

36+
/**
37+
* A utility class for managing and validating the multi-fields query format for the {@link LinearRetrieverBuilder} retriever.
38+
*/
3539
public class MultiFieldsInnerRetrieverUtils {
3640
private MultiFieldsInnerRetrieverUtils() {}
3741

3842
public record WeightedRetrieverSource(CompoundRetrieverBuilder.RetrieverSource retrieverSource, float weight) {}
3943

44+
/**
45+
* Validates the parameters related to the multi-fields query format.
46+
*
47+
* @param innerRetrievers The custom inner retrievers already defined
48+
* @param fields The fields to query
49+
* @param query The query text
50+
* @param retrieverName The containing retriever name
51+
* @param retrieversParamName The parameter name for custom inner retrievers
52+
* @param fieldsParamName The parameter name for the fields to query
53+
* @param queryParamName The parameter name for the query text
54+
* @param validationException The validation exception
55+
* @return The validation exception with any multi-fields query format validation errors appended
56+
*/
4057
public static ActionRequestValidationException validateParams(
4158
List<CompoundRetrieverBuilder.RetrieverSource> innerRetrievers,
4259
List<String> fields,
@@ -86,6 +103,33 @@ public static ActionRequestValidationException validateParams(
86103
return validationException;
87104
}
88105

106+
/**
107+
* Generate the inner retriever tree for the given fields, weights, and query. The tree follows this structure:
108+
*
109+
* <pre>
110+
* multi_match query on all lexical fields
111+
* normalizer retriever
112+
* match query on semantic_text field A
113+
* match query on semantic_text field B
114+
* ...
115+
* match query on semantic_text field Z
116+
* </pre>
117+
*
118+
* <p>
119+
* Where the normalizer retriever is constructed by the {@code innerNormalizerGenerator} function.
120+
* </p>
121+
* <p>
122+
* This tree structure is repeated for each index in {@code indicesMetadata}. That is to say, that for each index in
123+
* {@code indicesMetadata}, (up to) a pair of retrievers will be added to the returned {@code RetrieverBuilder} list.
124+
* </p>
125+
*
126+
* @param fieldsAndWeights The fields to query and their respective weights, in "field^weight" format
127+
* @param query The query text
128+
* @param indicesMetadata The metadata for the indices to search
129+
* @param innerNormalizerGenerator The inner normalizer retriever generator function
130+
* @param weightValidator The field weight validator
131+
* @return The inner retriever tree as a {@code RetrieverBuilder} list
132+
*/
89133
public static List<RetrieverBuilder> generateInnerRetrievers(
90134
List<String> fieldsAndWeights,
91135
String query,

0 commit comments

Comments
 (0)