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,15 @@ 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
+ // TODO lower this version once this has been backported to 6.0.0
114
+ if (in .getVersion ().before (Version .V_7_0_0_alpha1 )) {
115
+ MatchQuery .Type .readFromStream (in ); // deprecated type
116
+ }
127
117
operator = Operator .readFromStream (in );
128
- slop = in .readVInt ();
118
+ // TODO lower this version once this has been backported to 6.0.0
119
+ if (in .getVersion ().before (Version .V_7_0_0_alpha1 )) {
120
+ in .readVInt (); // deprecated slop
121
+ }
129
122
prefixLength = in .readVInt ();
130
123
maxExpansions = in .readVInt ();
131
124
fuzzyTranspositions = in .readBoolean ();
@@ -146,9 +139,15 @@ public MatchQueryBuilder(StreamInput in) throws IOException {
146
139
protected void doWriteTo (StreamOutput out ) throws IOException {
147
140
out .writeString (fieldName );
148
141
out .writeGenericValue (value );
149
- type .writeTo (out );
142
+ // TODO lower this version once this has been backported to 6.0.0
143
+ if (out .getVersion ().before (Version .V_7_0_0_alpha1 )) {
144
+ MatchQuery .Type .BOOLEAN .writeTo (out ); // deprecated type
145
+ }
150
146
operator .writeTo (out );
151
- out .writeVInt (slop );
147
+ // TODO lower this version once this has been backported to 6.0.0
148
+ if (out .getVersion ().before (Version .V_7_0_0_alpha1 )) {
149
+ out .writeVInt (MatchQuery .DEFAULT_PHRASE_SLOP ); // deprecated slop
150
+ }
152
151
out .writeVInt (prefixLength );
153
152
out .writeVInt (maxExpansions );
154
153
out .writeBoolean (fuzzyTranspositions );
@@ -175,34 +174,6 @@ public Object value() {
175
174
return this .value ;
176
175
}
177
176
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
177
/** Sets the operator to use when using a boolean query. Defaults to <tt>OR</tt>. */
207
178
public MatchQueryBuilder operator (Operator operator ) {
208
179
if (operator == null ) {
@@ -231,30 +202,6 @@ public String analyzer() {
231
202
return this .analyzer ;
232
203
}
233
204
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
205
/** Sets the fuzziness used when evaluated to a fuzzy query type. Defaults to "AUTO". */
259
206
public MatchQueryBuilder fuzziness (Object fuzziness ) {
260
207
this .fuzziness = Fuzziness .build (fuzziness );
@@ -425,18 +372,10 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
425
372
builder .startObject (fieldName );
426
373
427
374
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
375
builder .field (OPERATOR_FIELD .getPreferredName (), operator .toString ());
433
376
if (analyzer != null ) {
434
377
builder .field (ANALYZER_FIELD .getPreferredName (), analyzer );
435
378
}
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
379
if (fuzziness != null ) {
441
380
fuzziness .toXContent (builder , params );
442
381
}
@@ -473,7 +412,6 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
473
412
if (analyzer != null ) {
474
413
matchQuery .setAnalyzer (analyzer );
475
414
}
476
- matchQuery .setPhraseSlop (slop );
477
415
matchQuery .setFuzziness (fuzziness );
478
416
matchQuery .setFuzzyPrefixLength (prefixLength );
479
417
matchQuery .setMaxExpansions (maxExpansions );
@@ -484,18 +422,16 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
484
422
matchQuery .setZeroTermsQuery (zeroTermsQuery );
485
423
matchQuery .setAutoGenerateSynonymsPhraseQuery (autoGenerateSynonymsPhraseQuery );
486
424
487
- Query query = matchQuery .parse (type , fieldName , value );
425
+ Query query = matchQuery .parse (MatchQuery . Type . BOOLEAN , fieldName , value );
488
426
return Queries .maybeApplyMinimumShouldMatch (query , minimumShouldMatch );
489
427
}
490
428
491
429
@ Override
492
430
protected boolean doEquals (MatchQueryBuilder other ) {
493
431
return Objects .equals (fieldName , other .fieldName ) &&
494
432
Objects .equals (value , other .value ) &&
495
- Objects .equals (type , other .type ) &&
496
433
Objects .equals (operator , other .operator ) &&
497
434
Objects .equals (analyzer , other .analyzer ) &&
498
- Objects .equals (slop , other .slop ) &&
499
435
Objects .equals (fuzziness , other .fuzziness ) &&
500
436
Objects .equals (prefixLength , other .prefixLength ) &&
501
437
Objects .equals (maxExpansions , other .maxExpansions ) &&
@@ -510,7 +446,7 @@ protected boolean doEquals(MatchQueryBuilder other) {
510
446
511
447
@ Override
512
448
protected int doHashCode () {
513
- return Objects .hash (fieldName , value , type , operator , analyzer , slop ,
449
+ return Objects .hash (fieldName , value , operator , analyzer ,
514
450
fuzziness , prefixLength , maxExpansions , minimumShouldMatch ,
515
451
fuzzyRewrite , lenient , fuzzyTranspositions , zeroTermsQuery , cutoffFrequency , autoGenerateSynonymsPhraseQuery );
516
452
}
@@ -522,13 +458,11 @@ public String getWriteableName() {
522
458
523
459
public static MatchQueryBuilder fromXContent (XContentParser parser ) throws IOException {
524
460
String fieldName = null ;
525
- MatchQuery .Type type = MatchQuery .Type .BOOLEAN ;
526
461
Object value = null ;
527
462
float boost = AbstractQueryBuilder .DEFAULT_BOOST ;
528
463
String minimumShouldMatch = null ;
529
464
String analyzer = null ;
530
465
Operator operator = MatchQueryBuilder .DEFAULT_OPERATOR ;
531
- int slop = MatchQuery .DEFAULT_PHRASE_SLOP ;
532
466
Fuzziness fuzziness = null ;
533
467
int prefixLength = FuzzyQuery .defaultPrefixLength ;
534
468
int maxExpansion = FuzzyQuery .defaultMaxExpansions ;
@@ -553,23 +487,10 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc
553
487
} else if (token .isValue ()) {
554
488
if (QUERY_FIELD .match (currentFieldName )) {
555
489
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
490
} else if (ANALYZER_FIELD .match (currentFieldName )) {
568
491
analyzer = parser .text ();
569
492
} else if (AbstractQueryBuilder .BOOST_FIELD .match (currentFieldName )) {
570
493
boost = parser .floatValue ();
571
- } else if (SLOP_FIELD .match (currentFieldName )) {
572
- slop = parser .intValue ();
573
494
} else if (Fuzziness .FIELD .match (currentFieldName )) {
574
495
fuzziness = Fuzziness .parse (parser );
575
496
} else if (PREFIX_LENGTH_FIELD .match (currentFieldName )) {
@@ -624,9 +545,7 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc
624
545
625
546
MatchQueryBuilder matchQuery = new MatchQueryBuilder (fieldName , value );
626
547
matchQuery .operator (operator );
627
- matchQuery .type (type );
628
548
matchQuery .analyzer (analyzer );
629
- matchQuery .slop (slop );
630
549
matchQuery .minimumShouldMatch (minimumShouldMatch );
631
550
if (fuzziness != null ) {
632
551
matchQuery .fuzziness (fuzziness );
0 commit comments