@@ -138,10 +138,15 @@ public Page<RecruitBoardDetail> findAllNearby(RecruitBoardNearByCondition condit
138138 QLocation location = QLocation .location ;
139139 QCenter center = QCenter .center ;
140140
141+ List <RecruitBoardDocument > boardDocuments = getBoardDocuments (condition .keyword ());
142+
143+ List <Long > boardIds = boardDocuments .stream ()
144+ .map (RecruitBoardDocument ::getId )
145+ .toList ();
146+
141147 Pageable pageable = condition .pageable ();
142148
143149 BooleanExpression predicate = locationBetween (condition )
144- .and (keywordEq (condition .keyword ()))
145150 .and (statusEq (condition .status ()))
146151 .and (isNotDeleted ());
147152
@@ -150,7 +155,8 @@ public Page<RecruitBoardDetail> findAllNearby(RecruitBoardNearByCondition condit
150155 .from (recruitBoard )
151156 .join (location ).on (recruitBoard .locationId .eq (location .id ))
152157 .join (center ).on (recruitBoard .centerId .eq (center .id ))
153- .where (predicate )
158+ .where (recruitBoard .id .in (boardIds )
159+ .and (predicate ))
154160 .offset (pageable .getOffset ())
155161 .limit (pageable .getPageSize ())
156162 .orderBy (toOrderSpecifiers (pageable .getSort ()))
@@ -161,7 +167,8 @@ public Page<RecruitBoardDetail> findAllNearby(RecruitBoardNearByCondition condit
161167 .from (recruitBoard )
162168 .join (location ).on (recruitBoard .locationId .eq (location .id ))
163169 .join (center ).on (recruitBoard .centerId .eq (center .id ))
164- .where (predicate );
170+ .where (recruitBoard .id .in (boardIds )
171+ .and (predicate ));
165172
166173 return PageableExecutionUtils .getPage (content , pageable , countQuery ::fetchOne );
167174 }
@@ -197,11 +204,12 @@ public Page<RecruitBoard> findAllByCenterId(UUID centerId,
197204 }
198205
199206 @ Override
200- public Page <RecruitBoardWithCenter > findByRecruitBoardsContaining (String keyword , RecruitBoardSearchCondition condition ) {
207+ public Page <RecruitBoardWithCenter > findByRecruitBoardsContaining (RecruitBoardSearchCondition condition ) {
201208 QRecruitBoard recruitBoard = QRecruitBoard .recruitBoard ;
202209 QCenter center = QCenter .center ;
203210
204- List <RecruitBoardDocument > boardDocuments = documentRepository .findIdsByTitleOrContentContaining (keyword );
211+
212+ List <RecruitBoardDocument > boardDocuments = getBoardDocuments (condition .keyword ());
205213
206214 List <Long > boardIds = boardDocuments .stream ()
207215 .map (RecruitBoardDocument ::getId )
@@ -229,7 +237,8 @@ public Page<RecruitBoardWithCenter> findByRecruitBoardsContaining(String keyword
229237 .select (recruitBoard .count ())
230238 .from (recruitBoard )
231239 .join (center ).on (recruitBoard .centerId .eq (center .id ))
232- .where (predicate );
240+ .where (recruitBoard .id .in (boardIds )
241+ .and (predicate ));
233242
234243 return PageableExecutionUtils .getPage (content , pageable , countQuery ::fetchOne );
235244 }
@@ -361,4 +370,12 @@ private List<RecruitBoardDocument> convertEntityToDocuments(List<RecruitBoard> r
361370 }
362371 return communityBoardDocuments ;
363372 }
373+
374+ private List <RecruitBoardDocument > getBoardDocuments (String keyword ) {
375+
376+ if (keyword == null || keyword .isEmpty ()) {
377+ return documentRepository .findAll ();
378+ }
379+ return documentRepository .findIdsByTitleOrContentContaining (keyword );
380+ }
364381}
0 commit comments