‪TYPO3CMS  9.5
LiveSearchController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
23 
29 {
33  protected ‪$searchResults = [];
34 
41  public function ‪liveSearchAction(ServerRequestInterface $request): ResponseInterface
42  {
43  $queryString = trim($request->getQueryParams()['q']);
44  $liveSearch = GeneralUtility::makeInstance(LiveSearch::class);
45  $queryParser = GeneralUtility::makeInstance(QueryParser::class);
46 
47  ‪$searchResults = [];
48  $liveSearch->setQueryString($queryString);
49  // Jump & edit - find page and retrieve an edit link (this is only for pages
50  if ($queryParser->isValidPageJump($queryString)) {
51  $commandQuery = $queryParser->getCommandForPageJump($queryString);
52  if ($commandQuery) {
53  $queryString = $commandQuery;
54  }
55  }
56  // Search through the database and find records who match to the given search string
57  $resultArray = $liveSearch->find($queryString);
58  foreach ($resultArray as $resultFromTable) {
59  foreach ($resultFromTable as $item) {
60  ‪$searchResults[] = $item;
61  }
62  }
63  return (new ‪JsonResponse())->setPayload(‪$searchResults);
64  }
65 }
‪TYPO3\CMS\Backend\Controller\LiveSearchController\$searchResults
‪array $searchResults
Definition: LiveSearchController.php:32
‪TYPO3\CMS\Backend\Search\LiveSearch\LiveSearch
Definition: LiveSearch.php:38
‪TYPO3\CMS\Backend\Search\LiveSearch\QueryParser
Definition: QueryParser.php:23
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3
‪TYPO3\CMS\Backend\Controller\LiveSearchController\liveSearchAction
‪ResponseInterface liveSearchAction(ServerRequestInterface $request)
Definition: LiveSearchController.php:40
‪TYPO3\CMS\Backend\Controller\LiveSearchController
Definition: LiveSearchController.php:29