diff --git a/src/main/java/io/quarkus/search/app/SearchService.java b/src/main/java/io/quarkus/search/app/SearchService.java index 9146fe40..19947b63 100644 --- a/src/main/java/io/quarkus/search/app/SearchService.java +++ b/src/main/java/io/quarkus/search/app/SearchService.java @@ -80,8 +80,9 @@ public SearchResult search(@RestQuery @DefaultValue(QuarkusVersi .field(localizedField("fullContent_autocomplete", language)).boost(0.1f) .matching(q) // See: https://github.com/elastic/elasticsearch/issues/39905#issuecomment-471578025 - // while the issue is about stopwords the same problem is observed for synonyms on search-analyzer side: - .flags(SimpleQueryFlag.AND, SimpleQueryFlag.OR) + // while the issue is about stopwords the same problem is observed for synonyms on search-analyzer side. + // we also add phrase flag so that entire phrases could be searched as well, e.g.: "hibernate search" + .flags(SimpleQueryFlag.AND, SimpleQueryFlag.OR, SimpleQueryFlag.PHRASE) .defaultOperator(BooleanOperator.AND)) .should(f.match().field("origin").matching("quarkus").boost(50.0f)) .should(f.not(f.match().field(localizedField("topics", language)).matching("compatibility")) diff --git a/src/test/java/io/quarkus/search/app/SearchServiceTest.java b/src/test/java/io/quarkus/search/app/SearchServiceTest.java index adc896bb..100b7864 100644 --- a/src/test/java/io/quarkus/search/app/SearchServiceTest.java +++ b/src/test/java/io/quarkus/search/app/SearchServiceTest.java @@ -428,6 +428,20 @@ void quoteEmptyQuoteTitleTranslation() { "Duplicated context, context locals, asynchronous processing and propagation"); } + @Test + void searchForPhrase() { + var result = given() + .queryParam("q", "\"asynchronous processing and propagation\"") + .when().get(GUIDES_SEARCH) + .then() + .statusCode(200) + .extract().body().as(SEARCH_RESULT_SEARCH_HITS); + assertThat(result.hits()).extracting(GuideSearchHit::title) + .contains( + // unified highlighter will still "highlight" the phrase word by word: + "Duplicated context, context locals, asynchronous processing and propagation"); + } + private static ThrowingConsumer hitsHaveCorrectWordHighlighted(AtomicInteger matches, String word, String cssClass) { return sentence -> {