diff --git a/src/main/java/store/mybooks/front/elastic/controller/ElasticController.java b/src/main/java/store/mybooks/front/elastic/controller/ElasticController.java index e239ccfa..1d045c03 100644 --- a/src/main/java/store/mybooks/front/elastic/controller/ElasticController.java +++ b/src/main/java/store/mybooks/front/elastic/controller/ElasticController.java @@ -40,7 +40,7 @@ public String getSearchResultPage(@RequestParam("query") String query, Pageable pageable, Model model) { PageResponse result = elasticService.getSearchResultPage(query, pageable, order); - model.addAttribute("order", (order != null) ? order : "popular"); + model.addAttribute("order", (order != null) ? order : "accuracy"); if ("rate".equals(order)) { List checkReviewCount = result.getContent().stream() .filter(book -> book.getReviewCount() != null && book.getReviewCount() >= 100) diff --git a/src/main/java/store/mybooks/front/elastic/service/ElasticService.java b/src/main/java/store/mybooks/front/elastic/service/ElasticService.java index 8d5a2edd..88f9fea0 100644 --- a/src/main/java/store/mybooks/front/elastic/service/ElasticService.java +++ b/src/main/java/store/mybooks/front/elastic/service/ElasticService.java @@ -28,9 +28,14 @@ public class ElasticService { private final ElasticAdaptor elasticAdaptor; public PageResponse getSearchResultPage(String query, Pageable pageable, String order) { - if (order != null) { - Sort sort; + Sort sort; + if (order == null || order.equals("accuracy")) { + sort = Sort.by(Sort.Direction.DESC, "_score"); + } else { switch (order) { + case "popular": + sort = Sort.by(Sort.Direction.DESC, "book_view_count"); + break; case "recent": sort = Sort.by(Sort.Direction.DESC, "book_publish_date"); break; @@ -47,10 +52,10 @@ public PageResponse getSearchResultPage(String query, Pageabl sort = Sort.by(Sort.Direction.DESC, "book_review_count"); break; default: - sort = Sort.by(Sort.Direction.DESC, "book_view_count"); + sort = Sort.by(Sort.Direction.DESC, "_score"); } - pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); } + pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), sort); return elasticAdaptor.searchPaged(query, pageable); } }