+ * @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;
+ $results = collect();
+
+ if ($entityType !== 'all') {
+ $entityTypesToSearch = $entityType;
+ } else if (isset($terms['filters']['type'])) {
+ $entityTypesToSearch = explode('|', $terms['filters']['type']);
+ }
+
+ $total = 0;
+
+ foreach ($entityTypesToSearch as $entityType) {
+ if (!in_array($entityType, $entityTypes)) continue;
+ $search = $this->searchEntityTable($terms, $entityType, $page, $count);
+ $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