+ $total += $this->searchEntityTable($terms, $entityType, $page, $count, true);
+ $results = $results->merge($search);
+ }
+
+ return [
+ 'total' => $total,
+ 'count' => count($results),
+ 'results' => $results->sortByDesc('score')
+ ];
+ }
+
+
+ /**
+ * Search a book for entities
+ * @param integer $bookId
+ * @param string $searchString
+ * @return Collection
+ */
+ public function searchBook($bookId, $searchString)
+ {
+ $terms = $this->parseSearchString($searchString);
+ $entityTypes = ['page', 'chapter'];
+ $entityTypesToSearch = isset($terms['filters']['type']) ? explode('|', $terms['filters']['type']) : $entityTypes;
+
+ $results = collect();
+ foreach ($entityTypesToSearch as $entityType) {
+ if (!in_array($entityType, $entityTypes)) continue;
+ $search = $this->buildEntitySearchQuery($terms, $entityType)->where('book_id', '=', $bookId)->take(20)->get();