diff --git a/app/Search/SearchController.php b/app/Search/SearchController.php index 348d44a427f..0a57ff035ea 100644 --- a/app/Search/SearchController.php +++ b/app/Search/SearchController.php @@ -8,6 +8,7 @@ use BookStack\Http\Controller; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; +use BookStack\Users\Models\User; class SearchController extends Controller { @@ -17,9 +18,6 @@ public function __construct( ) { } - /** - * Searches all entities. - */ public function search(Request $request, SearchResultsFormatter $formatter) { $searchOpts = SearchOptions::fromRequest($request); @@ -27,6 +25,13 @@ public function search(Request $request, SearchResultsFormatter $formatter) $page = intval($request->get('page', '0')) ?: 1; $count = setting()->getInteger('lists-page-count-search', 18, 1, 1000); + $users = []; + if (!empty($fullSearchString)) { + $users = User::where('name', 'like', '%' . $fullSearchString . '%') + ->take(5) + ->get(); + } + $results = $this->searchRunner->searchEntities($searchOpts, 'all', $page, $count); $formatter->format($results['results']->all(), $searchOpts); $paginator = new LengthAwarePaginator($results['results'], $results['total'], $count, $page); @@ -41,23 +46,16 @@ public function search(Request $request, SearchResultsFormatter $formatter) 'paginator' => $paginator, 'searchTerm' => $fullSearchString, 'options' => $searchOpts, + 'users' => $users, ]); } - - /** - * Searches all entities within a book. - */ public function searchBook(Request $request, int $bookId) { - $term = $request->get('term', ''); + $term = $request->get('term', ''); $results = $this->searchRunner->searchBook($bookId, $term); return view('entities.list', ['entities' => $results]); } - - /** - * Searches all entities within a chapter. - */ public function searchChapter(Request $request, int $chapterId) { $term = $request->get('term', ''); @@ -76,7 +74,6 @@ public function searchForSelector(Request $request, QueryPopular $queryPopular) $searchTerm = $request->get('term', false); $permission = $request->get('permission', 'view'); - // Search for entities otherwise show most popular if ($searchTerm !== false) { $options = SearchOptions::fromString($searchTerm); $options->setFilter('type', implode('|', $entityTypes)); @@ -87,10 +84,6 @@ public function searchForSelector(Request $request, QueryPopular $queryPopular) return view('search.parts.entity-selector-list', ['entities' => $entities, 'permission' => $permission]); } - - /** - * Search for a list of templates to choose from. - */ public function templatesForSelector(Request $request) { $searchTerm = $request->get('term', false); @@ -112,14 +105,17 @@ public function templatesForSelector(Request $request) 'permission' => 'view' ]); } - - /** - * Search for a list of entities and return a partial HTML response of matching entities - * to be used as a result preview suggestion list for global system searches. - */ public function searchSuggestions(Request $request) { $searchTerm = $request->get('term', ''); + + $users = []; + if (!empty($searchTerm)) { + $users = User::where('name', 'like', '%' . $searchTerm . '%') + ->take(3) + ->get(); + } + $entities = $this->searchRunner->searchEntities(SearchOptions::fromString($searchTerm), 'all', 1, 5)['results']; foreach ($entities as $entity) { @@ -127,13 +123,10 @@ public function searchSuggestions(Request $request) } return view('search.parts.entity-suggestion-list', [ - 'entities' => $entities->slice(0, 5) + 'entities' => $entities->slice(0, 5), + 'users' => $users, ]); } - - /** - * Search sibling items in the system. - */ public function searchSiblings(Request $request, SiblingFetcher $siblingFetcher) { $type = $request->get('entity_type', null); @@ -143,4 +136,4 @@ public function searchSiblings(Request $request, SiblingFetcher $siblingFetcher) return view('entities.list-basic', ['entities' => $entities, 'style' => 'compact']); } -} +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index e8a1493d42f..4197e22d149 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,10 @@ { - "name": "bookstack", + "name": "BookStack", "lockfileVersion": 3, "requires": true, "packages": { "": { + "name": "BookStack", "dependencies": { "@codemirror/commands": "^6.10.0", "@codemirror/lang-css": "^6.3.1", @@ -3254,9 +3255,9 @@ } }, "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "version": "6.14.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.14.0.tgz", + "integrity": "sha512-IWrosm/yrn43eiKqkfkHis7QioDleaXQHdDVPKg0FSwwd/DuvyX79TZnFOnYpB7dcsFAMmtFztZuXPDvSePkFw==", "dev": true, "license": "MIT", "dependencies": { @@ -4215,9 +4216,9 @@ } }, "node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.4.tgz", + "integrity": "sha512-X07nttJQkwkfKfvTPG/KSnE2OMdcUCao6+eXF3wmnIQRn2aPAHH3VxDbDOdegkd6JbPsXqShpvEOHfAT+nCNwQ==", "dev": true, "license": "BSD-3-Clause", "engines": { @@ -5179,24 +5180,37 @@ "node": ">= 6" } }, + "node_modules/glob/node_modules/balanced-match": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", + "integrity": "sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "18 || 20 || >=22" + } + }, "node_modules/glob/node_modules/brace-expansion": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.2.tgz", - "integrity": "sha512-Jt0vHyM+jmUBqojB7E1NIYadt0vI0Qxjxd2TErW94wDz+E2LAm5vKMXXwg6ZZBTHPuUlDgQHKXvjGBdfcF1ZDQ==", + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.3.tgz", + "integrity": "sha512-fy6KJm2RawA5RcHkLa1z/ScpBeA762UF9KmZQxwIbDtRJrgLzM10depAiEQ+CXYcoiqW1/m96OAAoke2nE9EeA==", "dev": true, "license": "MIT", "dependencies": { - "balanced-match": "^1.0.0" + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "18 || 20 || >=22" } }, "node_modules/glob/node_modules/minimatch": { - "version": "9.0.5", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", - "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", + "version": "9.0.7", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.7.tgz", + "integrity": "sha512-MOwgjc8tfrpn5QQEvjijjmDVtMw2oL88ugTevzxQnzRLm6l3fVEF2gzU0kYeYYKD8C66+IdGX6peJ4MyUlUnPg==", "dev": true, "license": "ISC", "dependencies": { - "brace-expansion": "^2.0.1" + "brace-expansion": "^5.0.2" }, "engines": { "node": ">=16 || 14 >=14.17" @@ -7167,9 +7181,9 @@ } }, "node_modules/markdown-it": { - "version": "14.1.0", - "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.0.tgz", - "integrity": "sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==", + "version": "14.1.1", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-14.1.1.tgz", + "integrity": "sha512-BuU2qnTti9YKgK5N+IeMubp14ZUKUUw7yeJbkjtosvHiP0AZ5c8IAgEMk79D0eC8F23r4Ac/q8cAIFdm2FtyoA==", "license": "MIT", "dependencies": { "argparse": "^2.0.1", @@ -7245,9 +7259,9 @@ } }, "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.4.tgz", + "integrity": "sha512-twmL+S8+7yIsE9wsqgzU3E8/LumN3M3QELrBZ20OdmQ9jB2JvW5oZtBEmft84k/Gs5CG9mqtWc6Y9vW+JEzGxw==", "dev": true, "license": "ISC", "dependencies": { diff --git a/resources/views/search/all.blade.php b/resources/views/search/all.blade.php index 48250816fef..53af096ecf0 100644 --- a/resources/views/search/all.blade.php +++ b/resources/views/search/all.blade.php @@ -83,6 +83,23 @@