Skip to content

Commit

Permalink
Merge pull request #21 from yrodiere/title
Browse files Browse the repository at this point in the history
Provide title in search results
  • Loading branch information
yrodiere authored Oct 20, 2023
2 parents 6d9748d + d83255d commit cca84fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/io/quarkus/search/app/dto/SearchHit.java
Original file line number Diff line number Diff line change
@@ -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) {
}
13 changes: 13 additions & 0 deletions src/test/java/io/quarkus/search/app/SearchServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,17 @@ private static List<Arguments> 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"));
}
}

0 comments on commit cca84fd

Please sign in to comment.