22
33import com .querydsl .core .BooleanBuilder ;
44import com .querydsl .core .types .dsl .BooleanExpression ;
5+ import com .querydsl .core .types .dsl .Expressions ;
56import com .querydsl .jpa .impl .JPAQueryFactory ;
67import grep .neogulcoder .domain .recruitment .post .RecruitmentPost ;
78import grep .neogulcoder .domain .recruitment .post .controller .dto .response .QRecruitmentPostWithStudyInfo ;
@@ -71,22 +72,22 @@ public Page<RecruitmentPost> search(Pageable pageable, Category category, StudyT
7172
7273 equalsStudyCategory (category ),
7374 equalsStudyType (studyType ),
74- likeContent (keyword )
75+ likeContentFullText (keyword )
7576 )
7677 .offset (pageable .getOffset ())
7778 .limit (pageable .getPageSize ())
7879 .orderBy (recruitmentPost .createdDate .desc ())
7980 .fetch ();
8081
81- Long count = queryFactory .select (recruitmentPost .count ())
82+ Long count = queryFactory .select (recruitmentPost .id . count ())
8283 .from (recruitmentPost )
8384 .join (study ).on (recruitmentPost .studyId .eq (study .id ))
8485 .where (
8586 recruitmentPost .activated .isTrue (),
8687
8788 equalsStudyCategory (category ),
8889 equalsStudyType (studyType ),
89- likeContent (keyword )
90+ likeContentFullText (keyword )
9091 )
9192 .fetchOne ();
9293
@@ -103,15 +104,15 @@ public Page<RecruitmentPost> search(Pageable pageable, Category category, StudyT
103104
104105 equalsStudyCategory (category ),
105106 equalsStudyType (studyType ),
106- likeContent (keyword )
107+ likeContentFullText (keyword )
107108 )
108109 .offset (pageable .getOffset ())
109110 .limit (pageable .getPageSize ())
110111 .orderBy (recruitmentPost .createdDate .desc ())
111112 .fetch ();
112113
113114
114- Long count = queryFactory .select (recruitmentPost .count ())
115+ Long count = queryFactory .select (recruitmentPost .id . count ())
115116 .from (recruitmentPost )
116117 .join (study ).on (recruitmentPost .studyId .eq (study .id ))
117118 .where (
@@ -120,7 +121,7 @@ public Page<RecruitmentPost> search(Pageable pageable, Category category, StudyT
120121
121122 equalsStudyCategory (category ),
122123 equalsStudyType (studyType ),
123- likeContent (keyword )
124+ likeContentFullText (keyword )
124125 )
125126 .fetchOne ();
126127
@@ -145,8 +146,19 @@ private BooleanBuilder equalsStudyCategory(Category category) {
145146 return nullSafeBuilder (() -> study .category .eq (category ));
146147 }
147148
148- private BooleanBuilder likeContent (String content ) {
149- return nullSafeBuilder (() -> recruitmentPost .content .contains (content ).or (recruitmentPost .subject .contains (content )));
149+ private BooleanBuilder likeContentFullText (String content ) {
150+ return nullSafeBuilder (() -> {
151+ if (content == null || content .isBlank ()) {
152+ return null ;
153+ }
154+
155+ return Expressions .booleanTemplate (
156+ "function('match', {0}, {1}, {2}) > 0" ,
157+ recruitmentPost .content ,
158+ recruitmentPost .subject ,
159+ content
160+ );
161+ });
150162 }
151163
152164 private BooleanBuilder nullSafeBuilder (Supplier <BooleanExpression > supplier ) {
0 commit comments