Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/codeit/todo/domain/Goal.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name= "goal", indexes= @Index(name="idx_goal_goal_title", columnList = "goal_title"))
public class Goal {

@Id
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/codeit/todo/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name= "user", indexes= @Index(name="idx_user_name", columnList = "name"))
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/codeit/todo/repository/GoalRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public interface GoalRepository extends JpaRepository<Goal, Integer> {
""")
Slice<Goal> findByUserAndHasTodosAfterLastGoalId(@Param("lastGoalId") Integer lastGoalId, @Param("userId") int userId, Pageable pageable, @Param("today") LocalDate today);

List<Goal> findByGoalTitleContains(@Param("keyword") String keyword);
//List<Goal> findByGoalTitleContains(@Param("keyword") String keyword);


@Query(value = "SELECT * FROM goal WHERE MATCH(goal_title) AGAINST(:keyword IN BOOLEAN MODE) LIMIT 10000", nativeQuery = true)
List<Goal> searchByFullTextTitle(@Param("keyword") String keyword);

}
7 changes: 6 additions & 1 deletion src/main/java/com/codeit/todo/repository/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ public interface UserRepository extends JpaRepository<User, Integer> {

Optional<User> findByEmail(String email);

List<User> findByNameContains(@Param("keyword") String keyword);
//@Query(value = "SELECT * FROM user WHERE MATCH(name) AGAINST(:keyword IN BOOLEAN MODE) LIMIT 10000", nativeQuery = true)
//List<User> searchByFullTextName(@Param("keyword") String keyword);

List<User> findByNameStartingWith(@Param("keyword") String keyword);

//List<User> findByNameContains(@Param("keyword") String keyword);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public List<ReadSearchResponse> findUserAndGoal(int userId, ReadSearchRequest re
log.info("Starting search for field: {} with keyword: {}", searchField, keyword);

if( searchField.equals(SearchField.USER_NAME.getValue()) ){
List<User> searchedUsers = userRepository.findByNameContains(keyword);
List<User> searchedUsers = userRepository.findByNameStartingWith(keyword);
//List<User> searchedUsers = userRepository.findByNameContains(keyword);
//List<User> searchedUsers = userRepository.searchByFullTextName(keyword);
if(searchedUsers.isEmpty()) throw new SearchException(ErrorStatus.toErrorStatus("유저에 대한 검색 결과가 없습니다.", NOT_FOUND));

List<ReadSearchResponse> responses = searchedUsers.stream()
Expand All @@ -63,7 +65,8 @@ public List<ReadSearchResponse> findUserAndGoal(int userId, ReadSearchRequest re
return responses;

}else if(searchField.equals(SearchField.GOAL_TITLE.getValue())){
List<Goal> searchedGoals = goalRepository.findByGoalTitleContains(keyword);
List<Goal> searchedGoals = goalRepository.searchByFullTextTitle("+" + keyword + "*");
//List<Goal> searchedGoals = goalRepository.findByGoalTitleContains(keyword);
if(searchedGoals.isEmpty()) throw new SearchException(ErrorStatus.toErrorStatus("목표에 대한 검색 결과가 없습니다.", NOT_FOUND));

Map<User, List<Goal>> userGoalsMap = searchedGoals.stream()
Expand Down