21
21
22
22
import org .apache .lucene .search .FuzzyQuery ;
23
23
import org .apache .lucene .search .Query ;
24
+ import org .elasticsearch .Version ;
24
25
import org .elasticsearch .common .ParseField ;
25
26
import org .elasticsearch .common .ParsingException ;
26
27
import org .elasticsearch .common .io .stream .StreamInput ;
34
35
import org .elasticsearch .index .search .MatchQuery .ZeroTermsQuery ;
35
36
36
37
import java .io .IOException ;
37
- import java .util .Locale ;
38
38
import java .util .Objects ;
39
39
40
40
/**
41
41
* Match query is a query that analyzes the text and constructs a query as the
42
42
* result of the analysis.
43
43
*/
44
44
public class MatchQueryBuilder extends AbstractQueryBuilder <MatchQueryBuilder > {
45
- public static final ParseField SLOP_FIELD = new ParseField ("slop" , "phrase_slop" ).withAllDeprecated ("match_phrase query" );
46
45
public static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField ("zero_terms_query" );
47
46
public static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField ("cutoff_frequency" );
48
47
public static final ParseField LENIENT_FIELD = new ParseField ("lenient" );
@@ -53,7 +52,6 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
53
52
public static final ParseField MAX_EXPANSIONS_FIELD = new ParseField ("max_expansions" );
54
53
public static final ParseField PREFIX_LENGTH_FIELD = new ParseField ("prefix_length" );
55
54
public static final ParseField ANALYZER_FIELD = new ParseField ("analyzer" );
56
- public static final ParseField TYPE_FIELD = new ParseField ("type" ).withAllDeprecated ("match_phrase and match_phrase_prefix query" );
57
55
public static final ParseField QUERY_FIELD = new ParseField ("query" );
58
56
59
57
/** The name for the match query */
@@ -62,24 +60,14 @@ public class MatchQueryBuilder extends AbstractQueryBuilder<MatchQueryBuilder> {
62
60
/** The default mode terms are combined in a match query */
63
61
public static final Operator DEFAULT_OPERATOR = Operator .OR ;
64
62
65
- /** The default mode match query type */
66
- @ Deprecated
67
- public static final MatchQuery .Type DEFAULT_TYPE = MatchQuery .Type .BOOLEAN ;
68
-
69
63
private final String fieldName ;
70
64
71
65
private final Object value ;
72
66
73
- @ Deprecated
74
- private MatchQuery .Type type = DEFAULT_TYPE ;
75
-
76
67
private Operator operator = DEFAULT_OPERATOR ;
77
68
78
69
private String analyzer ;
79
70
80
- @ Deprecated
81
- private int slop = MatchQuery .DEFAULT_PHRASE_SLOP ;
82
-
83
71
private Fuzziness fuzziness = null ;
84
72
85
73
private int prefixLength = FuzzyQuery .defaultPrefixLength ;
@@ -119,9 +107,13 @@ public MatchQueryBuilder(StreamInput in) throws IOException {
119
107
super (in );
120
108
fieldName = in .readString ();
121
109
value = in .readGenericValue ();
122
- type = MatchQuery .Type .readFromStream (in );
110
+ if (in .getVersion ().before (Version .V_6_0_0_rc1 )) {
111
+ MatchQuery .Type .readFromStream (in ); // deprecated type
112
+ }
123
113
operator = Operator .readFromStream (in );
124
- slop = in .readVInt ();
114
+ if (in .getVersion ().before (Version .V_6_0_0_rc1 )) {
115
+ in .readVInt (); // deprecated slop
116
+ }
125
117
prefixLength = in .readVInt ();
126
118
maxExpansions = in .readVInt ();
127
119
fuzzyTranspositions = in .readBoolean ();
@@ -139,9 +131,13 @@ public MatchQueryBuilder(StreamInput in) throws IOException {
139
131
protected void doWriteTo (StreamOutput out ) throws IOException {
140
132
out .writeString (fieldName );
141
133
out .writeGenericValue (value );
142
- type .writeTo (out );
134
+ if (out .getVersion ().before (Version .V_6_0_0_rc1 )) {
135
+ MatchQuery .Type .BOOLEAN .writeTo (out ); // deprecated type
136
+ }
143
137
operator .writeTo (out );
144
- out .writeVInt (slop );
138
+ if (out .getVersion ().before (Version .V_6_0_0_rc1 )) {
139
+ out .writeVInt (MatchQuery .DEFAULT_PHRASE_SLOP ); // deprecated slop
140
+ }
145
141
out .writeVInt (prefixLength );
146
142
out .writeVInt (maxExpansions );
147
143
out .writeBoolean (fuzzyTranspositions );
@@ -165,34 +161,6 @@ public Object value() {
165
161
return this .value ;
166
162
}
167
163
168
- /**
169
- * Sets the type of the text query.
170
- *
171
- * @deprecated Use {@link MatchPhraseQueryBuilder} for <code>phrase</code>
172
- * queries and {@link MatchPhrasePrefixQueryBuilder} for
173
- * <code>phrase_prefix</code> queries
174
- */
175
- @ Deprecated
176
- public MatchQueryBuilder type (MatchQuery .Type type ) {
177
- if (type == null ) {
178
- throw new IllegalArgumentException ("[" + NAME + "] requires type to be non-null" );
179
- }
180
- this .type = type ;
181
- return this ;
182
- }
183
-
184
- /**
185
- * Get the type of the query.
186
- *
187
- * @deprecated Use {@link MatchPhraseQueryBuilder} for <code>phrase</code>
188
- * queries and {@link MatchPhrasePrefixQueryBuilder} for
189
- * <code>phrase_prefix</code> queries
190
- */
191
- @ Deprecated
192
- public MatchQuery .Type type () {
193
- return this .type ;
194
- }
195
-
196
164
/** Sets the operator to use when using a boolean query. Defaults to <tt>OR</tt>. */
197
165
public MatchQueryBuilder operator (Operator operator ) {
198
166
if (operator == null ) {
@@ -221,30 +189,6 @@ public String analyzer() {
221
189
return this .analyzer ;
222
190
}
223
191
224
- /**
225
- * Sets a slop factor for phrase queries
226
- *
227
- * @deprecated for phrase queries use {@link MatchPhraseQueryBuilder}
228
- */
229
- @ Deprecated
230
- public MatchQueryBuilder slop (int slop ) {
231
- if (slop < 0 ) {
232
- throw new IllegalArgumentException ("No negative slop allowed." );
233
- }
234
- this .slop = slop ;
235
- return this ;
236
- }
237
-
238
- /**
239
- * Get the slop factor for phrase queries.
240
- *
241
- * @deprecated for phrase queries use {@link MatchPhraseQueryBuilder}
242
- */
243
- @ Deprecated
244
- public int slop () {
245
- return this .slop ;
246
- }
247
-
248
192
/** Sets the fuzziness used when evaluated to a fuzzy query type. Defaults to "AUTO". */
249
193
public MatchQueryBuilder fuzziness (Object fuzziness ) {
250
194
this .fuzziness = Fuzziness .build (fuzziness );
@@ -401,18 +345,10 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio
401
345
builder .startObject (fieldName );
402
346
403
347
builder .field (QUERY_FIELD .getPreferredName (), value );
404
- // this is deprecated so only output the value if its not the default value (for bwc)
405
- if (type != MatchQuery .Type .BOOLEAN ) {
406
- builder .field (TYPE_FIELD .getPreferredName (), type .toString ().toLowerCase (Locale .ENGLISH ));
407
- }
408
348
builder .field (OPERATOR_FIELD .getPreferredName (), operator .toString ());
409
349
if (analyzer != null ) {
410
350
builder .field (ANALYZER_FIELD .getPreferredName (), analyzer );
411
351
}
412
- // this is deprecated so only output the value if its not the default value (for bwc)
413
- if (slop != MatchQuery .DEFAULT_PHRASE_SLOP ) {
414
- builder .field (SLOP_FIELD .getPreferredName (), slop );
415
- }
416
352
if (fuzziness != null ) {
417
353
fuzziness .toXContent (builder , params );
418
354
}
@@ -448,7 +384,6 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
448
384
if (analyzer != null ) {
449
385
matchQuery .setAnalyzer (analyzer );
450
386
}
451
- matchQuery .setPhraseSlop (slop );
452
387
matchQuery .setFuzziness (fuzziness );
453
388
matchQuery .setFuzzyPrefixLength (prefixLength );
454
389
matchQuery .setMaxExpansions (maxExpansions );
@@ -458,18 +393,16 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
458
393
matchQuery .setCommonTermsCutoff (cutoffFrequency );
459
394
matchQuery .setZeroTermsQuery (zeroTermsQuery );
460
395
461
- Query query = matchQuery .parse (type , fieldName , value );
396
+ Query query = matchQuery .parse (MatchQuery . Type . BOOLEAN , fieldName , value );
462
397
return Queries .maybeApplyMinimumShouldMatch (query , minimumShouldMatch );
463
398
}
464
399
465
400
@ Override
466
401
protected boolean doEquals (MatchQueryBuilder other ) {
467
402
return Objects .equals (fieldName , other .fieldName ) &&
468
403
Objects .equals (value , other .value ) &&
469
- Objects .equals (type , other .type ) &&
470
404
Objects .equals (operator , other .operator ) &&
471
405
Objects .equals (analyzer , other .analyzer ) &&
472
- Objects .equals (slop , other .slop ) &&
473
406
Objects .equals (fuzziness , other .fuzziness ) &&
474
407
Objects .equals (prefixLength , other .prefixLength ) &&
475
408
Objects .equals (maxExpansions , other .maxExpansions ) &&
@@ -483,7 +416,7 @@ protected boolean doEquals(MatchQueryBuilder other) {
483
416
484
417
@ Override
485
418
protected int doHashCode () {
486
- return Objects .hash (fieldName , value , type , operator , analyzer , slop ,
419
+ return Objects .hash (fieldName , value , operator , analyzer ,
487
420
fuzziness , prefixLength , maxExpansions , minimumShouldMatch ,
488
421
fuzzyRewrite , lenient , fuzzyTranspositions , zeroTermsQuery , cutoffFrequency );
489
422
}
@@ -495,13 +428,11 @@ public String getWriteableName() {
495
428
496
429
public static MatchQueryBuilder fromXContent (XContentParser parser ) throws IOException {
497
430
String fieldName = null ;
498
- MatchQuery .Type type = MatchQuery .Type .BOOLEAN ;
499
431
Object value = null ;
500
432
float boost = AbstractQueryBuilder .DEFAULT_BOOST ;
501
433
String minimumShouldMatch = null ;
502
434
String analyzer = null ;
503
435
Operator operator = MatchQueryBuilder .DEFAULT_OPERATOR ;
504
- int slop = MatchQuery .DEFAULT_PHRASE_SLOP ;
505
436
Fuzziness fuzziness = null ;
506
437
int prefixLength = FuzzyQuery .defaultPrefixLength ;
507
438
int maxExpansion = FuzzyQuery .defaultMaxExpansions ;
@@ -525,23 +456,10 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc
525
456
} else if (token .isValue ()) {
526
457
if (QUERY_FIELD .match (currentFieldName )) {
527
458
value = parser .objectText ();
528
- } else if (TYPE_FIELD .match (currentFieldName )) {
529
- String tStr = parser .text ();
530
- if ("boolean" .equals (tStr )) {
531
- type = MatchQuery .Type .BOOLEAN ;
532
- } else if ("phrase" .equals (tStr )) {
533
- type = MatchQuery .Type .PHRASE ;
534
- } else if ("phrase_prefix" .equals (tStr ) || ("phrasePrefix" .equals (tStr ))) {
535
- type = MatchQuery .Type .PHRASE_PREFIX ;
536
- } else {
537
- throw new ParsingException (parser .getTokenLocation (), "[" + NAME + "] query does not support type " + tStr );
538
- }
539
459
} else if (ANALYZER_FIELD .match (currentFieldName )) {
540
460
analyzer = parser .text ();
541
461
} else if (AbstractQueryBuilder .BOOST_FIELD .match (currentFieldName )) {
542
462
boost = parser .floatValue ();
543
- } else if (SLOP_FIELD .match (currentFieldName )) {
544
- slop = parser .intValue ();
545
463
} else if (Fuzziness .FIELD .match (currentFieldName )) {
546
464
fuzziness = Fuzziness .parse (parser );
547
465
} else if (PREFIX_LENGTH_FIELD .match (currentFieldName )) {
@@ -594,9 +512,7 @@ public static MatchQueryBuilder fromXContent(XContentParser parser) throws IOExc
594
512
595
513
MatchQueryBuilder matchQuery = new MatchQueryBuilder (fieldName , value );
596
514
matchQuery .operator (operator );
597
- matchQuery .type (type );
598
515
matchQuery .analyzer (analyzer );
599
- matchQuery .slop (slop );
600
516
matchQuery .minimumShouldMatch (minimumShouldMatch );
601
517
if (fuzziness != null ) {
602
518
matchQuery .fuzziness (fuzziness );
0 commit comments