|
6 | 6 |
|
7 | 7 | package org.elasticsearch.xpack.runtimefields.mapper;
|
8 | 8 |
|
| 9 | +import org.apache.lucene.search.MultiTermQuery.RewriteMethod; |
9 | 10 | import org.apache.lucene.search.Query;
|
10 | 11 | import org.apache.lucene.util.BytesRef;
|
| 12 | +import org.elasticsearch.common.geo.ShapeRelation; |
11 | 13 | import org.elasticsearch.common.lucene.BytesRefs;
|
| 14 | +import org.elasticsearch.common.time.DateMathParser; |
| 15 | +import org.elasticsearch.common.unit.Fuzziness; |
12 | 16 | import org.elasticsearch.common.xcontent.ToXContent.Params;
|
13 | 17 | import org.elasticsearch.common.xcontent.XContentBuilder;
|
14 | 18 | import org.elasticsearch.index.mapper.MappedFieldType;
|
|
18 | 22 | import org.elasticsearch.xpack.runtimefields.StringScriptFieldScript;
|
19 | 23 | import org.elasticsearch.xpack.runtimefields.fielddata.ScriptBinaryFieldData;
|
20 | 24 | import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldExistsQuery;
|
| 25 | +import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldFuzzyQuery; |
| 26 | +import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldPrefixQuery; |
| 27 | +import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldRangeQuery; |
| 28 | +import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldRegexpQuery; |
21 | 29 | import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldTermQuery;
|
22 | 30 | import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldTermsQuery;
|
| 31 | +import org.elasticsearch.xpack.runtimefields.query.StringScriptFieldWildcardQuery; |
23 | 32 |
|
24 | 33 | import java.io.IOException;
|
| 34 | +import java.time.ZoneId; |
25 | 35 | import java.util.List;
|
26 | 36 | import java.util.Map;
|
27 | 37 | import java.util.Objects;
|
@@ -69,18 +79,75 @@ private StringScriptFieldScript.LeafFactory leafFactory(QueryShardContext contex
|
69 | 79 |
|
70 | 80 | @Override
|
71 | 81 | public Query existsQuery(QueryShardContext context) {
|
72 |
| - return new StringScriptFieldExistsQuery(leafFactory(context), name()); |
| 82 | + return new StringScriptFieldExistsQuery(script, leafFactory(context), name()); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public Query fuzzyQuery( |
| 87 | + Object value, |
| 88 | + Fuzziness fuzziness, |
| 89 | + int prefixLength, |
| 90 | + int maxExpansions, |
| 91 | + boolean transpositions, |
| 92 | + QueryShardContext context |
| 93 | + ) { |
| 94 | + return StringScriptFieldFuzzyQuery.build( |
| 95 | + script, |
| 96 | + leafFactory(context), |
| 97 | + name(), |
| 98 | + BytesRefs.toString(Objects.requireNonNull(value)), |
| 99 | + fuzziness.asDistance(BytesRefs.toString(value)), |
| 100 | + prefixLength, |
| 101 | + transpositions |
| 102 | + ); |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public Query prefixQuery(String value, RewriteMethod method, org.elasticsearch.index.query.QueryShardContext context) { |
| 107 | + return new StringScriptFieldPrefixQuery(script, leafFactory(context), name(), value); |
| 108 | + } |
| 109 | + |
| 110 | + @Override |
| 111 | + public Query rangeQuery( |
| 112 | + Object lowerTerm, |
| 113 | + Object upperTerm, |
| 114 | + boolean includeLower, |
| 115 | + boolean includeUpper, |
| 116 | + ShapeRelation relation, |
| 117 | + ZoneId timeZone, |
| 118 | + DateMathParser parser, |
| 119 | + QueryShardContext context |
| 120 | + ) { |
| 121 | + return new StringScriptFieldRangeQuery( |
| 122 | + script, |
| 123 | + leafFactory(context), |
| 124 | + name(), |
| 125 | + BytesRefs.toString(Objects.requireNonNull(lowerTerm)), |
| 126 | + BytesRefs.toString(Objects.requireNonNull(upperTerm)), |
| 127 | + includeLower, |
| 128 | + includeUpper |
| 129 | + ); |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public Query regexpQuery(String value, int flags, int maxDeterminizedStates, RewriteMethod method, QueryShardContext context) { |
| 134 | + return new StringScriptFieldRegexpQuery(script, leafFactory(context), name(), value, flags, maxDeterminizedStates); |
73 | 135 | }
|
74 | 136 |
|
75 | 137 | @Override
|
76 | 138 | public Query termQuery(Object value, QueryShardContext context) {
|
77 |
| - return new StringScriptFieldTermQuery(leafFactory(context), name(), BytesRefs.toString(Objects.requireNonNull(value))); |
| 139 | + return new StringScriptFieldTermQuery(script, leafFactory(context), name(), BytesRefs.toString(Objects.requireNonNull(value))); |
78 | 140 | }
|
79 | 141 |
|
80 | 142 | @Override
|
81 | 143 | public Query termsQuery(List<?> values, QueryShardContext context) {
|
82 | 144 | Set<String> terms = values.stream().map(v -> BytesRefs.toString(Objects.requireNonNull(v))).collect(toSet());
|
83 |
| - return new StringScriptFieldTermsQuery(leafFactory(context), name(), terms); |
| 145 | + return new StringScriptFieldTermsQuery(script, leafFactory(context), name(), terms); |
| 146 | + } |
| 147 | + |
| 148 | + @Override |
| 149 | + public Query wildcardQuery(String value, RewriteMethod method, QueryShardContext context) { |
| 150 | + return new StringScriptFieldWildcardQuery(script, leafFactory(context), name(), value); |
84 | 151 | }
|
85 | 152 |
|
86 | 153 | void doXContentBody(XContentBuilder builder, boolean includeDefaults, Params params) throws IOException {
|
|
0 commit comments