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")); + } }