+ * @param int $count - Count of each entity to search, Total returned could can be larger and not guaranteed.
+ * @return array[int, Collection];
+ */
+ public function searchEntities($searchString, $entityType = 'all', $page = 1, $count = 20)
+ {
+ $terms = $this->parseSearchString($searchString);
+ $entityTypes = array_keys($this->entities);
+ $entityTypesToSearch = $entityTypes;
+
+ if ($entityType !== 'all') {
+ $entityTypesToSearch = $entityType;
+ } else if (isset($terms['filters']['type'])) {
+ $entityTypesToSearch = explode('|', $terms['filters']['type']);
+ }
+
+ $results = collect();
+ $total = 0;
+ $hasMore = false;
+
+ foreach ($entityTypesToSearch as $entityType) {
+ if (!in_array($entityType, $entityTypes)) {
+ continue;
+ }
+ $search = $this->searchEntityTable($terms, $entityType, $page, $count);
+ $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