|
15 | 15 | import org.apache.lucene.index.Term;
|
16 | 16 | import org.apache.lucene.search.BooleanClause;
|
17 | 17 | import org.apache.lucene.search.BooleanQuery;
|
| 18 | +import org.apache.lucene.search.ConstantScoreQuery; |
18 | 19 | import org.apache.lucene.search.MultiPhraseQuery;
|
19 | 20 | import org.apache.lucene.search.PhraseQuery;
|
20 | 21 | import org.apache.lucene.search.Query;
|
21 | 22 | import org.apache.lucene.search.TermQuery;
|
22 | 23 | import org.apache.lucene.tests.analysis.MockSynonymAnalyzer;
|
| 24 | +import org.opensearch.common.lucene.search.AutomatonQueries; |
23 | 25 | import org.opensearch.common.lucene.search.MultiPhrasePrefixQuery;
|
24 | 26 | import org.opensearch.core.common.Strings;
|
25 | 27 | import org.opensearch.core.xcontent.MediaTypeRegistry;
|
|
28 | 30 | import org.opensearch.index.query.MatchPhraseQueryBuilder;
|
29 | 31 | import org.opensearch.index.query.QueryShardContext;
|
30 | 32 | import org.opensearch.index.query.SourceFieldMatchQuery;
|
| 33 | +import org.opensearch.index.query.TermQueryBuilder; |
31 | 34 | import org.opensearch.index.search.MatchQuery;
|
32 | 35 | import org.junit.Before;
|
33 | 36 |
|
@@ -391,7 +394,7 @@ public void testPhraseQuery() throws IOException {
|
391 | 394 |
|
392 | 395 | assertThat(q, is(expectedQuery));
|
393 | 396 | Query q4 = new MatchPhraseQueryBuilder("field", "singleton").toQuery(queryShardContext);
|
394 |
| - assertThat(q4, is(new TermQuery(new Term("field", "singleton")))); |
| 397 | + assertThat(q4, is(new ConstantScoreQuery(new TermQuery(new Term("field", "singleton"))))); |
395 | 398 |
|
396 | 399 | Query q2 = new MatchPhraseQueryBuilder("field", "three words here").toQuery(queryShardContext);
|
397 | 400 | expectedQuery = new SourceFieldMatchQuery(
|
@@ -447,4 +450,22 @@ public void testPhraseQuery() throws IOException {
|
447 | 450 | );
|
448 | 451 | assertThat(q6, is(expectedQuery));
|
449 | 452 | }
|
| 453 | + |
| 454 | + public void testTermQuery() throws Exception { |
| 455 | + MapperService mapperService = createMapperService(mapping(b -> { |
| 456 | + b.startObject("field"); |
| 457 | + { |
| 458 | + b.field("type", textFieldName); |
| 459 | + b.field("analyzer", "my_stop_analyzer"); // "standard" will be replaced with MockSynonymAnalyzer |
| 460 | + } |
| 461 | + b.endObject(); |
| 462 | + })); |
| 463 | + QueryShardContext queryShardContext = createQueryShardContext(mapperService); |
| 464 | + |
| 465 | + Query q = new TermQueryBuilder("field", "foo").rewrite(queryShardContext).toQuery(queryShardContext); |
| 466 | + assertEquals(new ConstantScoreQuery(new TermQuery(new Term("field", "foo"))), q); |
| 467 | + |
| 468 | + q = new TermQueryBuilder("field", "foo").caseInsensitive(true).rewrite(queryShardContext).toQuery(queryShardContext); |
| 469 | + assertEquals(new ConstantScoreQuery(AutomatonQueries.caseInsensitiveTermQuery(new Term("field", "foo"))), q); |
| 470 | + } |
450 | 471 | }
|
0 commit comments