|
2 | 2 |
|
3 | 3 | import java.util.HashMap;
|
4 | 4 | import java.util.List;
|
| 5 | +import java.util.Locale; |
5 | 6 | import java.util.Map;
|
6 | 7 |
|
7 | 8 | import com.alibaba.druid.sql.ast.SQLExpr;
|
|
10 | 11 | import com.alibaba.druid.sql.ast.expr.SQLMethodInvokeExpr;
|
11 | 12 | import com.alibaba.druid.sql.ast.expr.SQLNumericLiteralExpr;
|
12 | 13 | import org.elasticsearch.common.Strings;
|
| 14 | +import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; |
13 | 15 | import org.elasticsearch.common.xcontent.ToXContent;
|
14 | 16 | import org.elasticsearch.index.query.*;
|
15 | 17 | import org.nlpcn.es4sql.Util;
|
16 | 18 | import org.nlpcn.es4sql.exception.SqlParseException;
|
17 | 19 |
|
18 | 20 | public class Paramer {
|
19 | 21 | private String analysis;
|
20 |
| - public Float boost; |
| 22 | + private Float boost; |
21 | 23 | public String value;
|
22 | 24 | public Integer slop;
|
23 | 25 |
|
24 |
| - public Map<String, Float> fieldsBoosts = new HashMap<>(); |
25 |
| - public String type; |
| 26 | + private Map<String, Float> fieldsBoosts = new HashMap<>(); |
| 27 | + private String type; |
26 | 28 | private Float tieBreaker;
|
27 |
| - public Operator operator; |
| 29 | + private Operator operator; |
28 | 30 |
|
29 | 31 | private String defaultField;
|
| 32 | + private String minimumShouldMatch; |
30 | 33 |
|
31 | 34 | private Boolean inOrder;
|
32 | 35 | public String clauses;
|
@@ -90,6 +93,9 @@ public static Paramer parseParamer(SQLMethodInvokeExpr method) throws SqlParseEx
|
90 | 93 | case "clauses":
|
91 | 94 | instance.clauses = Util.expr2Object(sqlExpr.getRight()).toString();
|
92 | 95 | break;
|
| 96 | + case "minimum_should_match": |
| 97 | + instance.minimumShouldMatch = Util.expr2Object(sqlExpr.getRight()).toString(); |
| 98 | + break; |
93 | 99 |
|
94 | 100 | default:
|
95 | 101 | break;
|
@@ -124,6 +130,15 @@ public static ToXContent fullParamer(MatchQueryBuilder query, Paramer paramer) {
|
124 | 130 | if (paramer.boost != null) {
|
125 | 131 | query.boost(paramer.boost);
|
126 | 132 | }
|
| 133 | + |
| 134 | + if (paramer.operator != null) { |
| 135 | + query.operator(paramer.operator); |
| 136 | + } |
| 137 | + |
| 138 | + if (paramer.minimumShouldMatch != null) { |
| 139 | + query.minimumShouldMatch(paramer.minimumShouldMatch); |
| 140 | + } |
| 141 | + |
127 | 142 | return query;
|
128 | 143 | }
|
129 | 144 |
|
@@ -151,6 +166,24 @@ public static ToXContent fullParamer(QueryStringQueryBuilder query, Paramer para
|
151 | 166 | query.defaultField(paramer.defaultField);
|
152 | 167 | }
|
153 | 168 |
|
| 169 | + if (paramer.tieBreaker != null) { |
| 170 | + query.tieBreaker(paramer.tieBreaker); |
| 171 | + } |
| 172 | + |
| 173 | + if (paramer.operator != null) { |
| 174 | + query.defaultOperator(paramer.operator); |
| 175 | + } |
| 176 | + |
| 177 | + if (paramer.type != null) { |
| 178 | + query.type(MultiMatchQueryBuilder.Type.parse(paramer.type.toLowerCase(Locale.ROOT), LoggingDeprecationHandler.INSTANCE)); |
| 179 | + } |
| 180 | + |
| 181 | + if (paramer.minimumShouldMatch != null) { |
| 182 | + query.minimumShouldMatch(paramer.minimumShouldMatch); |
| 183 | + } |
| 184 | + |
| 185 | + query.fields(paramer.fieldsBoosts); |
| 186 | + |
154 | 187 | return query;
|
155 | 188 | }
|
156 | 189 |
|
@@ -179,6 +212,12 @@ public static ToXContent fullParamer(MultiMatchQueryBuilder query, Paramer param
|
179 | 212 | query.operator(paramer.operator);
|
180 | 213 | }
|
181 | 214 |
|
| 215 | + if (paramer.minimumShouldMatch != null) { |
| 216 | + query.minimumShouldMatch(paramer.minimumShouldMatch); |
| 217 | + } |
| 218 | + |
| 219 | + query.fields(paramer.fieldsBoosts); |
| 220 | + |
182 | 221 | return query;
|
183 | 222 | }
|
184 | 223 |
|
|
0 commit comments