Showing
1 changed file
with
9 additions
and
3 deletions
| ... | @@ -97,10 +97,16 @@ class SearchService | ... | @@ -97,10 +97,16 @@ class SearchService |
| 97 | public function searchBook($bookId, $searchString) | 97 | public function searchBook($bookId, $searchString) |
| 98 | { | 98 | { |
| 99 | $terms = $this->parseSearchString($searchString); | 99 | $terms = $this->parseSearchString($searchString); |
| 100 | + $entityTypes = ['page', 'chapter']; | ||
| 101 | + $entityTypesToSearch = isset($terms['filters']['type']) ? explode('|', $terms['filters']['type']) : $entityTypes; | ||
| 102 | + | ||
| 100 | $results = collect(); | 103 | $results = collect(); |
| 101 | - $pages = $this->buildEntitySearchQuery($terms, 'page')->where('book_id', '=', $bookId)->take(20)->get(); | 104 | + foreach ($entityTypesToSearch as $entityType) { |
| 102 | - $chapters = $this->buildEntitySearchQuery($terms, 'chapter')->where('book_id', '=', $bookId)->take(20)->get(); | 105 | + if (!in_array($entityType, $entityTypes)) continue; |
| 103 | - return $results->merge($pages)->merge($chapters)->sortByDesc('score')->take(20); | 106 | + $search = $this->buildEntitySearchQuery($terms, $entityType)->where('book_id', '=', $bookId)->take(20)->get(); |
| 107 | + $results = $results->merge($search); | ||
| 108 | + } | ||
| 109 | + return $results->sortByDesc('score')->take(20); | ||
| 104 | } | 110 | } |
| 105 | 111 | ||
| 106 | /** | 112 | /** | ... | ... |
-
Please register or sign in to post a comment