Skip to content

Commit

Permalink
Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Oct 27, 2023
1 parent cb50af8 commit 299d344
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/io/quarkus/search/app/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
@Path("/")
public class SearchService {

private static final Integer PAGE_SIZE = 20;

@Inject
SearchSession session;

Expand All @@ -31,7 +33,8 @@ public class SearchService {
@Operation(summary = "Search for any resource")
@Transactional
public SearchResult<SearchHit> search(@RestQuery @DefaultValue(QuarkusVersions.LATEST) String version,
@RestQuery String q) {
@RestQuery String q,
@RestQuery @DefaultValue("0") int page) {
var result = session.search(Guide.class)
.select(SearchHit.class)
.where((f, root) -> {
Expand All @@ -57,7 +60,7 @@ public SearchResult<SearchHit> search(@RestQuery @DefaultValue(QuarkusVersions.L
}
})
.sort(f -> f.score().then().field("title_sort"))
.fetch(20);
.fetch(page * PAGE_SIZE, PAGE_SIZE);
return new SearchResult<>(result.total().hitCount(), result.hits());
}
}

0 comments on commit 299d344

Please sign in to comment.