35
35
import org .elasticsearch .index .search .MatchQuery .ZeroTermsQuery ;
36
36
37
37
import java .io .IOException ;
38
- import java .util .Locale ;
39
38
import java .util .Objects ;
40
39
41
40
/**
42
41
* Match query is a query that analyzes the text and constructs a query as the
43
42
* result of the analysis.
44
43
*/
45
44
public class MatchQueryBuilder extends AbstractQueryBuilder <MatchQueryBuilder > {
46
- public static final ParseField SLOP_FIELD = new ParseField ("slop" , "phrase_slop" ).withAllDeprecated ("match_phrase query" );
47
45
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField ("zero_terms_query" );
48
46
public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField ("cutoff_frequency" );
49
47
public static final ParseField LENIENT_FIELD = new ParseField ("lenient" );
@@ -54,7 +52,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
54
52
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField ("max_expansions" );
55
53
public static final ParseField PREFIX_LENGTH_FIELD = new ParseField ("prefix_length" );
56
54
public static final ParseField ANALYZER_FIELD = new ParseField ("analyzer" );
57
- public static final ParseField TYPE_FIELD = new ParseField ("type" ).withAllDeprecated ("match_phrase and match_phrase_prefix query" );
58
55
public static final ParseField QUERY_FIELD = new ParseField ("query" );
59
56
public static final ParseField GENERATE_SYNONYMS_PHRASE_QUERY = new ParseField ("auto_generate_synonyms_phrase_query" );
60
57
@@ -64,24 +61,14 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
64
61
/** The default mode terms are combined in a match query */
65
62
public static final Operator DEFAULT_OPERATOR = Operator .OR ;
66
63
67
- /** The default mode match query type */
68
- @ Deprecated
69
- public static final MatchQuery .Type DEFAULT_TYPE = MatchQuery .Type .BOOLEAN ;
70
-
71
64
private final String fieldName ;
72
65
73
66
private final Object value ;
74
67
75
- @ Deprecated
76
- private MatchQuery .Type type = DEFAULT_TYPE ;
77
-
78
68
private Operator operator = DEFAULT_OPERATOR ;
79
69
80
70
private String analyzer ;
81
71
82
- @ Deprecated
83
- private int slop = MatchQuery .DEFAULT_PHRASE_SLOP ;
84
-
85
72
private Fuzziness fuzziness = null ;
86
73
87
74
private int prefixLength = FuzzyQuery .defaultPrefixLength ;
@@ -123,9 +110,13 @@ public MatchQueryBuilder(StreamInput in) throws IOException {
123
110
super (in );
124
111
fieldName = in .readString ();
125
112
value = in .readGenericValue ();
126
- type = MatchQuery .Type .readFromStream (in );
113
+ if (in .getVersion ().before (Version .V_6_0_0_rc1 )) {
114
+ MatchQuery .Type .readFromStream (in ); // deprecated type
115
+ }
127
116
operator = Operator .readFromStream (in );
128
- slop = in .readVInt ();
117
+ if (in .getVersion ().before (Version .V_6_0_0_rc1 )) {
118
+ in .readVInt (); // deprecated slop
119
+ }
129
120
prefixLength = in .readVInt ();
130
121
maxExpansions = in .readVInt ();
131
122
fuzzyTranspositions = in .readBoolean ();
@@ -146,9 +137,13 @@ public MatchQueryBuilder(StreamInput in) throws IOException {
146
137
protected void doWriteTo (StreamOutput out ) throws IOException {
147
138
out .writeString (fieldName );
148
139
out .writeGenericValue (value );
149
- type .writeTo (out );
140
+ if (out .getVersion ().before (Version .V_6_0_0_rc1 )) {
141
+ MatchQuery .Type .BOOLEAN .writeTo (out ); // deprecated type
142
+ }
150
143
operator .writeTo (out );
151
- out .writeVInt (slop );
144
+ if (out .getVersion ().before (Version .V_6_0_0_rc1 )) {
145
+ out .writeVInt (MatchQuery .DEFAULT_PHRASE_SLOP ); // deprecated slop
146
+ }
152
147
out .writeVInt (prefixLength );
153
148
out .writeVInt (maxExpansions );
154
149
out .writeBoolean (fuzzyTranspositions );
@@ -175,34 +170,6 @@ public Object value() {
175
170
return this .value ;
176
171
}
177
172
178
- /**
179
- * Sets the type of the text query.
180
- *
181
- * @deprecated Use {@link MatchPhraseQueryBuilder} for <code>phrase</code>
182
- * queries and {@link MatchPhrasePrefixQueryBuilder} for
183
- * <code>phrase_prefix</code> queries
184
- */
185
- @ Deprecated
186
- public MatchQueryBuilder type (MatchQuery .Type type ) {
187
- if (type == null ) {
188
- throw new IllegalArgumentException ("[" + NAME + "] requires type to be non-null" );
189
- }
190
- this .type = type ;
191
- return this ;
192
- }
193
-
194
- /**
195
- * Get the type of the query.
196
- *
197
- * @deprecated Use {@link MatchPhraseQueryBuilder} for <code>phrase</code>
198
- * queries and {@link MatchPhrasePrefixQueryBuilder} for
199
- * <code>phrase_prefix</code> queries
200
- */
201
- @ Deprecated
202
- public MatchQuery .Type type () {
203
- return this .type ;
204
- }
205
-
206
173
/** Sets the operator to use when using a boolean query. Defaults to <tt>OR</tt>. */
207
174
public MatchQueryBuilder operator (Operator operator ) {
208
175
if (operator == null ) {
@@ -231,30 +198,6 @@ public String analyzer() {
231
198
return this .analyzer ;
232
199
}
233
200
234
- /**
235
- * Sets a slop factor for phrase queries
236
- *
237
- * @deprecated for phrase queries use {@link MatchPhraseQueryBuilder}
238
- */
239
- @ Deprecated
240
- public MatchQueryBuilder slop (int slop ) {
241
- if (slop < 0 ) {
242
- throw new IllegalArgumentException ("No negative slop allowed." );
243
- }
244
- this .slop = slop ;
245
- return this ;
246
- }
247
-
248
- /**
249
- * Get the slop factor for phrase queries.
250
- *
251
- * @deprecated for phrase queries use {@link MatchPhraseQueryBuilder}
252
- */
253
- @ Deprecated
254
- public int slop () {
255
- return this .slop ;
256
- }
257
-
258
201
/** Sets the fuzziness used when evaluated to a fuzzy query type. Defaults to "AUTO". */
259
202
public MatchQueryBuilder fuzziness (Object fuzziness ) {
260
203
this .fuzziness = Fuzziness .build (fuzziness );
@@ -425,18 +368,10 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
425
368
builder .startObject (fieldName );
426
369
427
370
builder .field (QUERY_FIELD .getPreferredName (), value );
428
- // this is deprecated so only output the value if its not the default value (for bwc)
429
- if (type != MatchQuery .Type .BOOLEAN ) {
430
- builder .field (TYPE_FIELD .getPreferredName (), type .toString ().toLowerCase (Locale .ENGLISH ));
431
- }
432
371
builder .field (OPERATOR_FIELD .getPreferredName (), operator .toString ());
433
372
if (analyzer != null ) {
434
373
builder .field (ANALYZER_FIELD .getPreferredName (), analyzer );
435
374
}
436
- // this is deprecated so only output the value if its not the default value (for bwc)
437
- if (slop != MatchQuery .DEFAULT_PHRASE_SLOP ) {
438
- builder .field (SLOP_FIELD .getPreferredName (), slop );
439
- }
440
375
if (fuzziness != null ) {
441
376
fuzziness .toXContent (builder , params );
442
377
}
@@ -473,7 +408,6 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
473
408
if (analyzer != null ) {
474
409
matchQuery .setAnalyzer (analyzer );
475
410
}
476
- matchQuery .setPhraseSlop (slop );
477
411
matchQuery .setFuzziness (fuzziness );
478
412
matchQuery .setFuzzyPrefixLength (prefixLength );
479
413
matchQuery .setMaxExpansions (maxExpansions );
@@ -484,18 +418,16 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
484
418
matchQuery .setZeroTermsQuery (zeroTermsQuery );
485
419
matchQuery .setAutoGenerateSynonymsPhraseQuery (autoGenerateSynonymsPhraseQuery );
486
420
487
- Query query = matchQuery .parse (type , fieldName , value );
421
+ Query query = matchQuery .parse (MatchQuery . Type . BOOLEAN , fieldName , value );
488
422
return Queries .maybeApplyMinimumShouldMatch (query , minimumShouldMatch );
489
423
}
490
424
491
425
@ Override
492
426
protected boolean doEquals (MatchQueryBuilder other ) {
493
427
return Objects .equals (fieldName , other .fieldName ) &&
494
428
Objects .equals (value , other .value ) &&
495
- Objects .equals (type , other .type ) &&
496
429
Objects .equals (operator , other .operator ) &&
497
430
Objects .equals (analyzer , other .analyzer ) &&
498
- Objects .equals (slop , other .slop ) &&
499
431
Objects .equals (fuzziness , other .fuzziness ) &&
500
432
Objects .equals (prefixLength , other .prefixLength ) &&
501
433
Objects .equals (maxExpansions , other .maxExpansions ) &&
@@ -510,7 +442,7 @@ protected boolean doEquals(MatchQueryBuilder other) {
510
442
511
443
@ Override
512
444
protected int doHashCode () {
513
- return Objects .hash (fieldName , value , type , operator , analyzer , slop ,
445
+ return Objects .hash (fieldName , value , operator , analyzer ,
514
446
fuzziness , prefixLength , maxExpansions , minimumShouldMatch ,
515
447
fuzzyRewrite , lenient , fuzzyTranspositions , zeroTermsQuery , cutoffFrequency , autoGenerateSynonymsPhraseQuery );
516
448
}
@@ -522,13 +454,11 @@ public String getWriteableName() {
522
454
523
455
public static MatchQueryBuilder fromXContent (XContentParser parser ) throws IOException {
524
456
String fieldName = null ;
525
- MatchQuery .Type type = MatchQuery .Type .BOOLEAN ;
526
457
Object value = null ;
527
458
float boost = AbstractQueryBuilder .DEFAULT_BOOST ;
528
459
String minimumShouldMatch = null ;
529
460
String analyzer = null ;
530
461
Operator operator = MatchQueryBuilder .DEFAULT_OPERATOR ;
531
- int slop = MatchQuery .DEFAULT_PHRASE_SLOP ;
532
462
Fuzziness fuzziness = null ;
533
463
int prefixLength = FuzzyQuery .defaultPrefixLength ;
534
464
int maxExpansion = FuzzyQuery .defaultMaxExpansions ;
@@ -553,23 +483,10 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc
553
483
} else if (token .isValue ()) {
554
484
if (QUERY_FIELD .match (currentFieldName )) {
555
485
value = parser .objectText ();
556
- } else if (TYPE_FIELD .match (currentFieldName )) {
557
- String tStr = parser .text ();
558
- if ("boolean" .equals (tStr )) {
559
- type = MatchQuery .Type .BOOLEAN ;
560
- } else if ("phrase" .equals (tStr )) {
561
- type = MatchQuery .Type .PHRASE ;
562
- } else if ("phrase_prefix" .equals (tStr ) || ("phrasePrefix" .equals (tStr ))) {
563
- type = MatchQuery .Type .PHRASE_PREFIX ;
564
- } else {
565
- throw new ParsingException (parser .getTokenLocation (), "[" + NAME + "] query does not support type " + tStr );
566
- }
567
486
} else if (ANALYZER_FIELD .match (currentFieldName )) {
568
487
analyzer = parser .text ();
569
488
} else if (AbstractQueryBuilder .BOOST_FIELD .match (currentFieldName )) {
570
489
boost = parser .floatValue ();
571
- } else if (SLOP_FIELD .match (currentFieldName )) {
572
- slop = parser .intValue ();
573
490
} else if (Fuzziness .FIELD .match (currentFieldName )) {
574
491
fuzziness = Fuzziness .parse (parser );
575
492
} else if (PREFIX_LENGTH_FIELD .match (currentFieldName )) {
@@ -624,9 +541,7 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc
624
541
625
542
MatchQueryBuilder matchQuery = new MatchQueryBuilder (fieldName , value );
626
543
matchQuery .operator (operator );
627
- matchQuery .type (type );
628
544
matchQuery .analyzer (analyzer );
629
- matchQuery .slop (slop );
630
545
matchQuery .minimumShouldMatch (minimumShouldMatch );
631
546
if (fuzziness != null ) {
632
547
matchQuery .fuzziness (fuzziness );
0 commit comments