Skip to content

Commit 1d63d80

Browse files
committed
HSEARCH-4536 Test empty sets of flags in regexp and simplequerystring predicates
1 parent 4e28644 commit 1d63d80

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

integrationtest/backend/tck/src/main/java/org/hibernate/search/integrationtest/backend/tck/search/predicate/RegexpPredicateSpecificsIT.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import static org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery;
1010

11+
import java.util.Collections;
1112
import java.util.function.Function;
1213

1314
import org.hibernate.search.engine.backend.common.DocumentReference;
@@ -165,6 +166,13 @@ public void flag_complement() {
165166
.matching( TEXT_COMPLEMENT ) ) )
166167
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
167168

169+
// no flag at all (same as default)
170+
assertThatQuery( scope.query()
171+
.where( f -> f.regexp().field( absoluteFieldPath )
172+
.matching( TEXT_COMPLEMENT )
173+
.flags( Collections.emptySet() ) ) )
174+
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
175+
168176
// alone
169177
assertThatQuery( scope.query()
170178
.where( f -> f.regexp().field( absoluteFieldPath )
@@ -201,6 +209,13 @@ public void flag_interval() {
201209
.matching( TEXT_INTERVAL ) ) )
202210
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
203211

212+
// no flag at all (same as default)
213+
assertThatQuery( scope.query()
214+
.where( f -> f.regexp().field( absoluteFieldPath )
215+
.matching( TEXT_INTERVAL )
216+
.flags( Collections.emptySet() ) ) )
217+
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
218+
204219
// alone
205220
assertThatQuery( scope.query()
206221
.where( f -> f.regexp().field( absoluteFieldPath )
@@ -237,6 +252,13 @@ public void flag_intersection() {
237252
.matching( TEXT_INTERSECTION ) ) )
238253
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
239254

255+
// no flag at all (same as default)
256+
assertThatQuery( scope.query()
257+
.where( f -> f.regexp().field( absoluteFieldPath )
258+
.matching( TEXT_INTERSECTION )
259+
.flags( Collections.emptySet() ) ) )
260+
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
261+
240262
// alone
241263
assertThatQuery( scope.query()
242264
.where( f -> f.regexp().field( absoluteFieldPath )
@@ -273,6 +295,13 @@ public void flag_anyString() {
273295
.matching( TEXT_ANYSTRING ) ) )
274296
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
275297

298+
// no flag at all (same as default)
299+
assertThatQuery( scope.query()
300+
.where( f -> f.regexp().field( absoluteFieldPath )
301+
.matching( TEXT_ANYSTRING )
302+
.flags( Collections.emptySet() ) ) )
303+
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1 );
304+
276305
// alone
277306
assertThatQuery( scope.query()
278307
.where( f -> f.regexp().field( absoluteFieldPath )

integrationtest/backend/tck/src/main/java/org/hibernate/search/integrationtest/backend/tck/search/predicate/SimpleQueryStringPredicateSpecificsIT.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1010
import static org.hibernate.search.util.impl.integrationtest.common.assertion.SearchResultAssert.assertThatQuery;
1111

12+
import java.util.Collections;
1213
import java.util.EnumSet;
1314
import java.util.function.Function;
1415

@@ -123,6 +124,13 @@ public void booleanOperators_flags() {
123124
.toQuery() )
124125
// "OR" disabled: "+" is dropped during analysis and we end up with "term1 + term2", since AND is the default operator
125126
.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 );
126134

127135
String andQueryString = TERM_1 + " + " + TERM_2;
128136
assertThatQuery( scope.query().where( f -> f.simpleQueryString().field( absoluteFieldPath )
@@ -138,6 +146,13 @@ public void booleanOperators_flags() {
138146
.toQuery() )
139147
// "AND" disabled: "+" is dropped during analysis and we end up with "term1 | term2", since OR is the default operator
140148
.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 );
141156

142157
String notQueryString = "-" + TERM_1 + " + " + TERM_2;
143158
assertThatQuery( scope.query().where( f -> f.simpleQueryString().field( absoluteFieldPath )
@@ -151,6 +166,12 @@ public void booleanOperators_flags() {
151166
.toQuery() )
152167
// "NOT" disabled: "-" is dropped during analysis and we end up with "term1 + term2"
153168
.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 );
154175

155176
// Don't use a whitespace here: there's a bug in ES6.2 that leads the "("/")",
156177
// when interpreted as an (empty) term, to be turned into a match-no-docs query.
@@ -166,6 +187,12 @@ public void booleanOperators_flags() {
166187
.toQuery() )
167188
// "PRECENDENCE" disabled: parentheses are dropped during analysis and we end up with "(term2 + term1) | term3"
168189
.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 );
169196
}
170197

171198
@Test
@@ -272,6 +299,12 @@ public void phrase_flag() {
272299
.toQuery() )
273300
.hasDocRefHitsAnyOrder( index.typeName(), DOCUMENT_1, DOCUMENT_3 );
274301

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+
275308
// Slop
276309
assertThatQuery( scope.query()
277310
.where( f -> f.simpleQueryString().field( absoluteFieldPath )
@@ -286,6 +319,12 @@ public void phrase_flag() {
286319
.flags( EnumSet.complementOf( EnumSet.of( SimpleQueryFlag.NEAR ) ) ) )
287320
.toQuery() )
288321
.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 );
289328
}
290329

291330
@Test
@@ -327,6 +366,12 @@ public void fuzzy_flag() {
327366
.flags( EnumSet.complementOf( EnumSet.of( SimpleQueryFlag.FUZZY ) ) ) )
328367
.toQuery() )
329368
.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 );
330375
}
331376

332377
@Test
@@ -364,6 +409,12 @@ public void prefix_flag() {
364409
.flags( EnumSet.complementOf( EnumSet.of( SimpleQueryFlag.PREFIX ) ) ) )
365410
.toQuery() )
366411
.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();
367418
}
368419

369420
@Test

0 commit comments

Comments
 (0)