|
33 | 33 | import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper; |
34 | 34 | import org.elasticsearch.xpack.esql.expression.function.Example; |
35 | 35 | import org.elasticsearch.xpack.esql.expression.function.FunctionInfo; |
36 | | -import org.elasticsearch.xpack.esql.expression.function.OptionalArgument; |
37 | 36 | import org.elasticsearch.xpack.esql.expression.function.Param; |
| 37 | +import org.elasticsearch.xpack.esql.expression.function.TwoOptionalArguments; |
38 | 38 | import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction; |
39 | 39 | import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput; |
40 | 40 | import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates; |
|
44 | 44 | import org.elasticsearch.xpack.esql.querydsl.query.TranslationAwareExpressionQuery; |
45 | 45 |
|
46 | 46 | import java.io.IOException; |
| 47 | +import java.util.ArrayList; |
47 | 48 | import java.util.List; |
48 | 49 | import java.util.Map; |
49 | 50 | import java.util.Objects; |
|
60 | 61 | /** |
61 | 62 | * Extract snippets function, that extracts the most relevant snippets from a given input string |
62 | 63 | */ |
63 | | -public class ExtractSnippets extends EsqlScalarFunction implements OptionalArgument, RewriteableAware, TranslationAware, EvaluatorMapper { |
| 64 | +public class ExtractSnippets extends EsqlScalarFunction |
| 65 | + implements |
| 66 | + TwoOptionalArguments, |
| 67 | + RewriteableAware, |
| 68 | + TranslationAware, |
| 69 | + EvaluatorMapper { |
64 | 70 | public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry( |
65 | 71 | Expression.class, |
66 | 72 | "ExtractSnippets", |
@@ -108,7 +114,7 @@ public ExtractSnippets( |
108 | 114 | Expression snippetLength, |
109 | 115 | QueryBuilder queryBuilder |
110 | 116 | ) { |
111 | | - super(source, List.of(field, str, numSnippets, snippetLength)); |
| 117 | + super(source, fields(field, str, numSnippets, snippetLength)); |
112 | 118 | this.field = field; |
113 | 119 | this.str = str; |
114 | 120 | this.numSnippets = numSnippets; |
@@ -331,4 +337,17 @@ public boolean equals(Object o) { |
331 | 337 | public int hashCode() { |
332 | 338 | return Objects.hash(field(), str(), numSnippets(), snippetLength(), queryBuilder()); |
333 | 339 | } |
| 340 | + |
| 341 | + private static List<Expression> fields(Expression field, Expression str, Expression numSnippets, Expression snippetLength) { |
| 342 | + List<Expression> list = new ArrayList<>(4); |
| 343 | + list.add(field); |
| 344 | + list.add(str); |
| 345 | + if (numSnippets != null) { |
| 346 | + list.add(numSnippets); |
| 347 | + if (snippetLength != null) { |
| 348 | + list.add(snippetLength); |
| 349 | + } |
| 350 | + } |
| 351 | + return list; |
| 352 | + } |
334 | 353 | } |
0 commit comments