From d83255dbd3957d8f8a9fb056720fa30a005d3a56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Fri, 20 Oct 2023 16:20:30 +0200 Subject: [PATCH] Provide title in search results --- .../java/io/quarkus/search/app/dto/SearchHit.java | 3 ++- .../io/quarkus/search/app/SearchServiceTest.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/quarkus/search/app/dto/SearchHit.java b/src/main/java/io/quarkus/search/app/dto/SearchHit.java index 4e7567d6..f321ae20 100644 --- a/src/main/java/io/quarkus/search/app/dto/SearchHit.java +++ b/src/main/java/io/quarkus/search/app/dto/SearchHit.java @@ -1,8 +1,9 @@ package io.quarkus.search.app.dto; +import org.hibernate.search.mapper.pojo.mapping.definition.annotation.FieldProjection; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.IdProjection; import org.hibernate.search.mapper.pojo.mapping.definition.annotation.ProjectionConstructor; @ProjectionConstructor -public record SearchHit(@IdProjection String id) { +public record SearchHit(@IdProjection String id, @FieldProjection String title) { } diff --git a/src/test/java/io/quarkus/search/app/SearchServiceTest.java b/src/test/java/io/quarkus/search/app/SearchServiceTest.java index a1b68432..500c196a 100644 --- a/src/test/java/io/quarkus/search/app/SearchServiceTest.java +++ b/src/test/java/io/quarkus/search/app/SearchServiceTest.java @@ -187,4 +187,17 @@ private static List relevance_params() { Arguments.of("spring data", List.of( GuideIds.SPRING_DATA_JPA))); } + + @Test + public void projections() { + var result = given() + .queryParam("q", "hibernate + elasticsearch") + .when().get() + .then() + .statusCode(200) + .extract().body().as(SEARCH_RESULT_SEARCH_HITS); + assertThat(result.hits()).containsExactlyInAnyOrder( + new SearchHit(GuideIds.HIBERNATE_SEARCH_ORM_ELASTICSEARCH, + "Hibernate Search guide")); + } }