|
43 | 43 | import static org.elasticsearch.action.ValidateActions.addValidationError;
|
44 | 44 | import static org.elasticsearch.xcontent.ConstructingObjectParser.optionalConstructorArg;
|
45 | 45 | import static org.elasticsearch.xpack.rank.RankRRFFeatures.LINEAR_RETRIEVER_SUPPORTED;
|
| 46 | +import static org.elasticsearch.xpack.rank.linear.LinearRetrieverComponent.DEFAULT_NORMALIZER; |
46 | 47 | import static org.elasticsearch.xpack.rank.linear.LinearRetrieverComponent.DEFAULT_WEIGHT;
|
47 | 48 |
|
48 | 49 | /**
|
@@ -82,17 +83,17 @@ public final class LinearRetrieverBuilder extends CompoundRetrieverBuilder<Linea
|
82 | 83 | List<LinearRetrieverComponent> retrieverComponents = args[0] == null ? List.of() : (List<LinearRetrieverComponent>) args[0];
|
83 | 84 | List<String> fields = (List<String>) args[1];
|
84 | 85 | String query = (String) args[2];
|
85 |
| - ScoreNormalizer normalizer = args[3] == null ? null : ScoreNormalizer.valueOf((String) args[3]); |
| 86 | + ScoreNormalizer normalizer = args[3] == null ? DEFAULT_NORMALIZER : ScoreNormalizer.valueOf((String) args[3]); |
86 | 87 | int rankWindowSize = args[4] == null ? RankBuilder.DEFAULT_RANK_WINDOW_SIZE : (int) args[4];
|
87 | 88 |
|
88 | 89 | int index = 0;
|
89 | 90 | float[] weights = new float[retrieverComponents.size()];
|
90 | 91 | ScoreNormalizer[] normalizers = new ScoreNormalizer[retrieverComponents.size()];
|
| 92 | + Arrays.fill(normalizers, normalizer); |
91 | 93 | List<RetrieverSource> innerRetrievers = new ArrayList<>();
|
92 | 94 | for (LinearRetrieverComponent component : retrieverComponents) {
|
93 | 95 | innerRetrievers.add(RetrieverSource.from(component.retriever));
|
94 | 96 | weights[index] = component.weight;
|
95 |
| - normalizers[index] = component.normalizer; |
96 | 97 | index++;
|
97 | 98 | }
|
98 | 99 | return new LinearRetrieverBuilder(innerRetrievers, fields, query, normalizer, rankWindowSize, weights, normalizers);
|
@@ -221,17 +222,6 @@ public ActionRequestValidationException validate(
|
221 | 222 | ),
|
222 | 223 | validationException
|
223 | 224 | );
|
224 |
| - } else if (innerRetrievers.isEmpty() == false && normalizer != null) { |
225 |
| - validationException = addValidationError( |
226 |
| - String.format( |
227 |
| - Locale.ROOT, |
228 |
| - "[%s] [%s] cannot be provided when [%s] is specified", |
229 |
| - getName(), |
230 |
| - NORMALIZER_FIELD.getPreferredName(), |
231 |
| - RETRIEVERS_FIELD.getPreferredName() |
232 |
| - ), |
233 |
| - validationException |
234 |
| - ); |
235 | 225 | }
|
236 | 226 |
|
237 | 227 | return validationException;
|
@@ -393,7 +383,6 @@ public void doToXContent(XContentBuilder builder, Params params) throws IOExcept
|
393 | 383 | builder.startObject();
|
394 | 384 | builder.field(LinearRetrieverComponent.RETRIEVER_FIELD.getPreferredName(), entry.retriever());
|
395 | 385 | builder.field(LinearRetrieverComponent.WEIGHT_FIELD.getPreferredName(), weights[index]);
|
396 |
| - builder.field(LinearRetrieverComponent.NORMALIZER_FIELD.getPreferredName(), normalizers[index].getName()); |
397 | 386 | builder.endObject();
|
398 | 387 | index++;
|
399 | 388 | }
|
|
0 commit comments