diff --git a/Classes/Controller/SearchController.php b/Classes/Controller/SearchController.php index 51af8a2..f4f9299 100644 --- a/Classes/Controller/SearchController.php +++ b/Classes/Controller/SearchController.php @@ -22,7 +22,7 @@ namespace Codappix\SearchCore\Controller; */ use Codappix\SearchCore\Domain\Model\SearchRequest; -use Codappix\SearchCore\Domain\Search\SearchService; +use Codappix\SearchCore\Domain\Search\CachedSearchService; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; /** @@ -31,14 +31,14 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; class SearchController extends ActionController { /** - * @var SearchService + * @var CachedSearchService */ protected $searchService; /** - * @param SearchService $searchService + * @param CachedSearchService $searchService */ - public function __construct(SearchService $searchService) + public function __construct(CachedSearchService $searchService) { $this->searchService = $searchService; diff --git a/Classes/Domain/Index/AbstractIndexer.php b/Classes/Domain/Index/AbstractIndexer.php index 37e2f29..3e3bc55 100644 --- a/Classes/Domain/Index/AbstractIndexer.php +++ b/Classes/Domain/Index/AbstractIndexer.php @@ -168,7 +168,7 @@ abstract class AbstractIndexer implements IndexerInterface } catch (InvalidArgumentException $e) { // Nothing to do. } - $this->generateSearchIdentifier($record); + $this->generateSearchIdentifiers($record); $this->handleAbstract($record); } @@ -176,8 +176,11 @@ abstract class AbstractIndexer implements IndexerInterface * @param array $record * @return void */ - protected function generateSearchIdentifier(array &$record) + protected function generateSearchIdentifiers(array &$record) { + if (!isset($record['search_document'])) { + $record['search_document_type'] = $this->getDocumentName(); + } if (!isset($record['search_identifier']) && isset($record['uid'])) { $record['search_identifier'] = $this->getDocumentName() . '-' . $record['uid']; } diff --git a/Classes/Domain/Search/CachedSearchService.php b/Classes/Domain/Search/CachedSearchService.php new file mode 100644 index 0000000..76d746b --- /dev/null +++ b/Classes/Domain/Search/CachedSearchService.php @@ -0,0 +1,55 @@ +searchService = $searchService; + } + + /** + * @param SearchRequestInterface $searchRequest + * @return SearchResultInterface + */ + public function search(SearchRequestInterface $searchRequest): SearchResultInterface + { + $hash = $this->getHash($searchRequest); + if (isset($this->results[$hash]) && $this->results[$hash] instanceof SearchResultInterface) { + return $this->results[$hash]; + } + return $this->results[$hash] = $this->searchService->search($searchRequest); + } + + /** + * @param SearchRequestInterface $searchRequest + * @return string + */ + protected function getHash(SearchRequestInterface $searchRequest): string + { + if (is_callable([$searchRequest, 'getRequestHash'])) { + return (string)$searchRequest->getRequestHash(); + } + return sha1(serialize($searchRequest)); + } + +} diff --git a/Resources/Private/Partials/Results/ListItem.html b/Resources/Private/Partials/Results/ListItem.html index 7844e32..1ef408b 100644 --- a/Resources/Private/Partials/Results/ListItem.html +++ b/Resources/Private/Partials/Results/ListItem.html @@ -1,8 +1,8 @@ - - [{result.type}:{result.plainData.uid}] - {result.plainData.search_title} + + [{result.search_document_type}:{result.uid}] - {result.search_title}