1 | <?php |
||
40 | class SuggestController extends AbstractBaseController |
||
41 | { |
||
42 | /** |
||
43 | * This method creates a suggest json response that can be used in a suggest layer. |
||
44 | * |
||
45 | * @param string $queryString |
||
46 | * @param string $callback |
||
47 | * @return string |
||
48 | */ |
||
49 | public function suggestAction($queryString, $callback) |
||
50 | { |
||
51 | $jsonPCallback = htmlspecialchars($callback); |
||
52 | // Get suggestions |
||
53 | $rawQuery = htmlspecialchars(mb_strtolower(trim($queryString))); |
||
54 | |||
55 | try { |
||
56 | /** @var SuggestService $suggestService */ |
||
57 | $suggestService = GeneralUtility::makeInstance(SuggestService::class, $this->typoScriptFrontendController, $this->searchService, $this->typoScriptConfiguration); |
||
58 | $additionalFilters = htmlspecialchars(GeneralUtility::_GET('filters')); |
||
59 | |||
60 | $pageId = $this->typoScriptFrontendController->getRequestedId(); |
||
61 | $languageId = $this->typoScriptFrontendController->sys_language_uid; |
||
62 | $arguments = (array)$this->request->getArguments(); |
||
63 | $searchRequest = $this->getSearchRequestBuilder()->buildForSuggest($arguments, $rawQuery, $pageId, $languageId); |
||
64 | $result = $suggestService->getSuggestions($searchRequest, $additionalFilters); |
||
65 | } catch (SolrUnavailableException $e) { |
||
66 | $this->handleSolrUnavailable(); |
||
67 | $result = ['status' => false]; |
||
68 | } |
||
69 | |||
70 | return htmlspecialchars($jsonPCallback) . '(' . json_encode($result) . ')'; |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Called when the solr server is unavailable. |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | protected function handleSolrUnavailable() |
||
86 | |||
87 | } |
||
88 |