Skip to content

Commit

Permalink
refactor: 도서검색 정확도순 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
newjaehun committed Mar 27, 2024
1 parent 37a294c commit 6922474
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String getSearchResultPage(@RequestParam("query") String query,
Pageable pageable, Model model) {
PageResponse<BookBriefResponse> 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<BookBriefResponse> checkReviewCount = result.getContent().stream()
.filter(book -> book.getReviewCount() != null && book.getReviewCount() >= 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ public class ElasticService {
private final ElasticAdaptor elasticAdaptor;

public PageResponse<BookBriefResponse> 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;
Expand All @@ -47,10 +52,10 @@ public PageResponse<BookBriefResponse> 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);
}
}

0 comments on commit 6922474

Please sign in to comment.