Skip to content

Commit

Permalink
fix: 검색에 정렬 기능 제거
Browse files Browse the repository at this point in the history
  • Loading branch information
kmg159753 committed Jul 25, 2023
1 parent 82ce7fe commit e553a85
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,13 @@ public ResponseEntity<Map<String, Object>> getNewsByCategory(
public ResponseEntity<Map<String, Object>> SearchNews(
@RequestParam("keyword") String keyword,
@RequestParam("page") int page,
@RequestParam("size") int size,
@RequestParam("sortBy") String sortBy,
@RequestParam("isAsc") boolean isAsc
@RequestParam("size") int size
) {

Map<String, Object> newsResponseDtoList = newsService.SearchNews(
keyword,
page - 1,
size,
sortBy,
isAsc
size
);

return ResponseEntity.ok(newsResponseDtoList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ public interface NewsRepository extends JpaRepository<News,Long> {

@Query(
value =
"SELECT * FROM news WHERE MATCH(title, content) AGAINST (:keyword) " +
"ORDER BY :orderField :orderDirection " +
"SELECT * FROM news WHERE MATCH(title, content) AGAINST (:keyword) "+
"LIMIT :limit OFFSET :offset", nativeQuery = true
)
List<News> fullTextSearchNewsByKeyWordNativeVer(
@Param("keyword") String keyword,
@Param("limit") int limit,
@Param("offset") int offset,
@Param("orderField") String orderField,
@Param("orderDirection") String orderDirection
@Param("offset") int offset
);

@Query(
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/com/example/newnique/news/service/NewsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,14 @@ public Map<String, Object> getNewsByCategory(String category, int page, int size
}

public Map<String, Object> SearchNews(String keyword, int page,
int size, String sortBy, boolean isAsc) {
int size) {

Sort.Direction direction = isAsc ? Sort.Direction.ASC : Sort.Direction.DESC;
Sort sort = Sort.by(direction, sortBy);
Pageable pageable = PageRequest.of(page, size, sort);
Pageable pageable = PageRequest.of(page, size);

List<News> newsListByCategory = newsRepository.fullTextSearchNewsByKeyWordNativeVer(
keyword,
pageable.getPageSize(),
(int)pageable.getOffset(),
sortBy,
"Desc"
(int)pageable.getOffset()
);

Map<String, Object> response = new HashMap<>();
Expand Down

0 comments on commit e553a85

Please sign in to comment.