9
9
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
10
10
import static org .hibernate .search .util .impl .integrationtest .common .assertion .SearchResultAssert .assertThatQuery ;
11
11
12
+ import java .util .Collections ;
12
13
import java .util .EnumSet ;
13
14
import java .util .function .Function ;
14
15
@@ -123,6 +124,13 @@ public void booleanOperators_flags() {
123
124
.toQuery () )
124
125
// "OR" disabled: "+" is dropped during analysis and we end up with "term1 + term2", since AND is the default operator
125
126
.hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 );
127
+ assertThatQuery ( scope .query ().where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
128
+ .matching ( orQueryString )
129
+ .defaultOperator ( BooleanOperator .AND )
130
+ .flags ( Collections .emptySet () ) ) )
131
+ // All flags disabled: operators are dropped during analysis (empty tokens)
132
+ // and we end up with "term1 + term2", since AND is the default operator.
133
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 );
126
134
127
135
String andQueryString = TERM_1 + " + " + TERM_2 ;
128
136
assertThatQuery ( scope .query ().where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
@@ -138,6 +146,13 @@ public void booleanOperators_flags() {
138
146
.toQuery () )
139
147
// "AND" disabled: "+" is dropped during analysis and we end up with "term1 | term2", since OR is the default operator
140
148
.hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 , DOCUMENT_3 );
149
+ assertThatQuery ( scope .query ().where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
150
+ .matching ( andQueryString )
151
+ .defaultOperator ( BooleanOperator .OR )
152
+ .flags ( Collections .emptySet () ) ) )
153
+ // All flags disabled: operators are dropped during analysis (empty tokens)
154
+ // and we end up with "term1 | term2", since OR is the default operator.
155
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 , DOCUMENT_3 );
141
156
142
157
String notQueryString = "-" + TERM_1 + " + " + TERM_2 ;
143
158
assertThatQuery ( scope .query ().where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
@@ -151,6 +166,12 @@ public void booleanOperators_flags() {
151
166
.toQuery () )
152
167
// "NOT" disabled: "-" is dropped during analysis and we end up with "term1 + term2"
153
168
.hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 );
169
+ assertThatQuery ( scope .query ().where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
170
+ .matching ( notQueryString )
171
+ .flags ( Collections .emptySet () ) ) )
172
+ // All flags disabled: operators are dropped during analysis (empty tokens)
173
+ // and we end up with "term1 | term2", since OR is the default operator.
174
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 , DOCUMENT_3 );
154
175
155
176
// Don't use a whitespace here: there's a bug in ES6.2 that leads the "("/")",
156
177
// when interpreted as an (empty) term, to be turned into a match-no-docs query.
@@ -166,6 +187,12 @@ public void booleanOperators_flags() {
166
187
.toQuery () )
167
188
// "PRECENDENCE" disabled: parentheses are dropped during analysis and we end up with "(term2 + term1) | term3"
168
189
.hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 );
190
+ assertThatQuery ( scope .query ().where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
191
+ .matching ( precedenceQueryString )
192
+ .flags ( Collections .emptySet () ) ) )
193
+ // All flags disabled: operators are dropped during analysis (empty tokens)
194
+ // and we end up with "term2 | term1 | term3", since OR is the default operator.
195
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 , DOCUMENT_3 );
169
196
}
170
197
171
198
@ Test
@@ -272,6 +299,12 @@ public void phrase_flag() {
272
299
.toQuery () )
273
300
.hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_3 );
274
301
302
+ assertThatQuery ( scope .query ()
303
+ .where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
304
+ .matching ( "\" " + PHRASE_WITH_TERM_2 + "\" " )
305
+ .flags ( Collections .emptySet () ) ) )
306
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_3 );
307
+
275
308
// Slop
276
309
assertThatQuery ( scope .query ()
277
310
.where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
@@ -286,6 +319,12 @@ public void phrase_flag() {
286
319
.flags ( EnumSet .complementOf ( EnumSet .of ( SimpleQueryFlag .NEAR ) ) ) )
287
320
.toQuery () )
288
321
.hasNoHits ();
322
+
323
+ assertThatQuery ( scope .query ()
324
+ .where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
325
+ .matching ( "\" " + PHRASE_WITH_TERM_4 + "\" ~2" )
326
+ .flags ( Collections .emptySet () ) ) )
327
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_4 );
289
328
}
290
329
291
330
@ Test
@@ -327,6 +366,12 @@ public void fuzzy_flag() {
327
366
.flags ( EnumSet .complementOf ( EnumSet .of ( SimpleQueryFlag .FUZZY ) ) ) )
328
367
.toQuery () )
329
368
.hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 );
369
+
370
+ assertThatQuery ( scope .query ()
371
+ .where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
372
+ .matching ( TERM_1 + "~1" )
373
+ .flags ( Collections .emptySet () ) ) )
374
+ .hasDocRefHitsAnyOrder ( index .typeName (), DOCUMENT_1 , DOCUMENT_2 );
330
375
}
331
376
332
377
@ Test
@@ -364,6 +409,12 @@ public void prefix_flag() {
364
409
.flags ( EnumSet .complementOf ( EnumSet .of ( SimpleQueryFlag .PREFIX ) ) ) )
365
410
.toQuery () )
366
411
.hasNoHits ();
412
+
413
+ assertThatQuery ( scope .query ()
414
+ .where ( f -> f .simpleQueryString ().field ( absoluteFieldPath )
415
+ .matching ( PREFIX_FOR_TERM_1_AND_TERM_6 + "*" )
416
+ .flags ( Collections .emptySet () ) ) )
417
+ .hasNoHits ();
367
418
}
368
419
369
420
@ Test
0 commit comments