|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.esql.expression.function.fulltext; |
9 | 9 |
|
| 10 | +import org.apache.lucene.util.BytesRef; |
10 | 11 | import org.elasticsearch.ElasticsearchParseException; |
11 | 12 | import org.elasticsearch.TransportVersions; |
12 | 13 | import org.elasticsearch.common.io.stream.NamedWriteableRegistry; |
|
23 | 24 | import org.elasticsearch.xpack.esql.core.tree.NodeInfo; |
24 | 25 | import org.elasticsearch.xpack.esql.core.tree.Source; |
25 | 26 | import org.elasticsearch.xpack.esql.core.type.DataType; |
| 27 | +import org.elasticsearch.xpack.esql.core.type.DataTypeConverter; |
26 | 28 | import org.elasticsearch.xpack.esql.expression.function.Example; |
27 | 29 | import org.elasticsearch.xpack.esql.expression.function.FunctionInfo; |
28 | 30 | import org.elasticsearch.xpack.esql.expression.function.Param; |
|
33 | 35 | import java.util.ArrayList; |
34 | 36 | import java.util.List; |
35 | 37 |
|
| 38 | +import static org.elasticsearch.common.logging.LoggerMessageFormat.format; |
36 | 39 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FIRST; |
37 | 40 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.FOURTH; |
38 | 41 | import static org.elasticsearch.xpack.esql.core.expression.TypeResolutions.ParamOrdinal.SECOND; |
@@ -143,14 +146,14 @@ protected TypeResolution resolveNonQueryParamTypes() { |
143 | 146 | .and(super.resolveNonQueryParamTypes()); |
144 | 147 | if (boost != null) { |
145 | 148 | typeResolution = typeResolution.and( |
146 | | - isNotNull(boost, sourceText(), THIRD).and(isNumeric(field, sourceText(), THIRD).and(isFoldable(field, sourceText(), THIRD))) |
| 149 | + isNotNull(boost, sourceText(), THIRD).and(isNumeric(boost, sourceText(), THIRD).and(isFoldable(boost, sourceText(), THIRD))) |
147 | 150 | ); |
148 | 151 | } |
149 | 152 | if (fuzziness != null) { |
150 | 153 | typeResolution = typeResolution.and( |
151 | 154 | isNotNull(fuzziness, sourceText(), FOURTH).and( |
152 | | - isType(fuzziness, dt -> dt == DataType.INTEGER, sourceText(), FOURTH, "integer,keyword").or( |
153 | | - isString(fuzziness, sourceText(), FOURTH).and(isFoldable(fuzziness, sourceText(), FOURTH)) |
| 155 | + isType(fuzziness, dt -> dt == DataType.INTEGER || dt == DataType.KEYWORD, sourceText(), FOURTH, "integer,keyword").and( |
| 156 | + isFoldable(fuzziness, sourceText(), FOURTH) |
154 | 157 | ) |
155 | 158 | ) |
156 | 159 | ); |
@@ -206,14 +209,24 @@ public Double boost() { |
206 | 209 | if (boost == null) { |
207 | 210 | return null; |
208 | 211 | } |
209 | | - return (Double) boost.fold(); |
| 212 | + return (Double) DataTypeConverter.convert(boost.fold(), DataType.DOUBLE); |
210 | 213 | } |
211 | 214 |
|
212 | 215 | public Fuzziness fuzziness() { |
213 | 216 | if (fuzziness == null) { |
214 | 217 | return null; |
215 | 218 | } |
216 | | - return Fuzziness.fromString(fuzziness.fold().toString()); |
| 219 | + |
| 220 | + Object fuzinessAsObject = fuzziness.fold(); |
| 221 | + if (fuzinessAsObject instanceof BytesRef bytesRefValue) { |
| 222 | + return Fuzziness.fromString(bytesRefValue.utf8ToString()); |
| 223 | + } else if (fuzinessAsObject instanceof Integer intValue) { |
| 224 | + return Fuzziness.fromEdits(intValue); |
| 225 | + } |
| 226 | + |
| 227 | + throw new IllegalArgumentException( |
| 228 | + format(null, "{} argument in {} {} needs to be resolved to a string or integer", THIRD, functionName(), functionType()) |
| 229 | + ); |
217 | 230 | } |
218 | 231 |
|
219 | 232 | @Override |
|
0 commit comments