@@ -72,9 +72,9 @@ public function searchBook(int $bookId, string $searchString): Collection
7272 $ entityTypesToSearch = isset ($ filterMap ['type ' ]) ? explode ('| ' , $ filterMap ['type ' ]) : $ entityTypes ;
7373
7474 $ filteredTypes = array_intersect ($ entityTypesToSearch , $ entityTypes );
75- $ results = $ this ->buildQuery ($ opts , $ filteredTypes )->where ('book_id ' , '= ' , $ bookId)-> take ( 20 )-> get ( );
75+ $ query = $ this ->buildQuery ($ opts , $ filteredTypes )->where ('book_id ' , '= ' , $ bookId );
7676
77- return $ results -> sortByDesc ( ' score ' )->take ( 20 );
77+ return $ this -> getPageOfDataFromQuery ( $ query , 1 , 20 )->sortByDesc ( ' score ' );
7878 }
7979
8080 /**
@@ -83,9 +83,9 @@ public function searchBook(int $bookId, string $searchString): Collection
8383 public function searchChapter (int $ chapterId , string $ searchString ): Collection
8484 {
8585 $ opts = SearchOptions::fromString ($ searchString );
86- $ pages = $ this ->buildQuery ($ opts , ['page ' ])->where ('chapter_id ' , '= ' , $ chapterId)-> take ( 20 )-> get ( );
86+ $ query = $ this ->buildQuery ($ opts , ['page ' ])->where ('chapter_id ' , '= ' , $ chapterId );
8787
88- return $ pages ->sortByDesc ('score ' );
88+ return $ this -> getPageOfDataFromQuery ( $ query , 1 , 20 ) ->sortByDesc ('score ' );
8989 }
9090
9191 /**
@@ -120,7 +120,8 @@ protected function buildQuery(SearchOptions $searchOpts, array $entityTypes): El
120120 $ filter = function (EloquentBuilder $ query ) use ($ exact ) {
121121 $ inputTerm = str_replace ('\\' , '\\\\' , $ exact ->value );
122122 $ query ->where ('name ' , 'like ' , '% ' . $ inputTerm . '% ' )
123- ->orWhere ('description ' , 'like ' , '% ' . $ inputTerm . '% ' );
123+ ->orWhere ('description ' , 'like ' , '% ' . $ inputTerm . '% ' )
124+ ->orWhere ('text ' , 'like ' , '% ' . $ inputTerm . '% ' );
124125 };
125126
126127 $ exact ->negated ? $ entityQuery ->whereNot ($ filter ) : $ entityQuery ->where ($ filter );
@@ -301,7 +302,7 @@ protected function applyTagSearch(EloquentBuilder $query, TagSearchOption $optio
301302 $ option ->negated ? $ query ->whereDoesntHave ('tags ' , $ filter ) : $ query ->whereHas ('tags ' , $ filter );
302303 }
303304
304- protected function applyNegatableWhere (EloquentBuilder $ query , bool $ negated , string $ column , string $ operator , mixed $ value ): void
305+ protected function applyNegatableWhere (EloquentBuilder $ query , bool $ negated , string | callable $ column , string | null $ operator , mixed $ value ): void
305306 {
306307 if ($ negated ) {
307308 $ query ->whereNot ($ column , $ operator , $ value );
@@ -376,7 +377,10 @@ protected function filterInTitle(EloquentBuilder $query, string $input, bool $ne
376377
377378 protected function filterInBody (EloquentBuilder $ query , string $ input , bool $ negated )
378379 {
379- $ this ->applyNegatableWhere ($ query , $ negated , 'description ' , 'like ' , '% ' . $ input . '% ' );
380+ $ this ->applyNegatableWhere ($ query , $ negated , function (EloquentBuilder $ query ) use ($ input ) {
381+ $ query ->where ('description ' , 'like ' , '% ' . $ input . '% ' )
382+ ->orWhere ('text ' , 'like ' , '% ' . $ input . '% ' );
383+ }, null , null );
380384 }
381385
382386 protected function filterIsRestricted (EloquentBuilder $ query , string $ input , bool $ negated )
0 commit comments