+ $entityTotal = $this->searchEntityTable($terms, $entityType, $page, $count, true);
+ if ($entityTotal > $page * $count) {
+ $hasMore = true;
+ }
+ $total += $entityTotal;
+ $results = $results->merge($search);
+ }
+
+ return [
+ 'total' => $total,
+ 'count' => count($results),
+ 'has_more' => $hasMore,
+ 'results' => $results->sortByDesc('score')->values()
+ ];
+ }
+
+
+ /**
+ * 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();