mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-26 09:56:11 +01:00
TASK: Remove cache implementation
As it does not use TYPO3 caching framework but custom feature.
This commit is contained in:
parent
a6f7f31274
commit
4c99009ea0
4 changed files with 7 additions and 78 deletions
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Codappix\SearchCore\Domain\Search;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2018 Benjamin Serfhos <benjamin@serfhos.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301, USA.
|
||||
*/
|
||||
|
||||
use Codappix\SearchCore\Connection\SearchRequestInterface;
|
||||
use Codappix\SearchCore\Connection\SearchResultInterface;
|
||||
use TYPO3\CMS\Core\SingletonInterface;
|
||||
|
||||
/**
|
||||
* Service to process a search request, only once per request.
|
||||
*/
|
||||
class CachedSearchService implements SingletonInterface, SearchServiceInterface
|
||||
{
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $results = [];
|
||||
|
||||
/**
|
||||
* @var SearchService
|
||||
*/
|
||||
protected $searchService;
|
||||
|
||||
public function __construct(SearchService $searchService)
|
||||
{
|
||||
$this->searchService = $searchService;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public function processResult(SearchResultInterface $searchResult): SearchResultInterface
|
||||
{
|
||||
return $this->searchService->processResult($searchResult);
|
||||
}
|
||||
|
||||
protected function getHash(SearchRequestInterface $searchRequest): string
|
||||
{
|
||||
if (is_callable([$searchRequest, 'getRequestHash'])) {
|
||||
return (string)$searchRequest->getRequestHash();
|
||||
}
|
||||
return sha1(serialize($searchRequest));
|
||||
}
|
||||
}
|
|
@ -25,8 +25,8 @@ Some interfaces and abstract classes have been adjusted:
|
|||
Also some exceptions have changed:
|
||||
|
||||
* ``Codappix\SearchCore\Connection\Elasticsearch\DocumentFactory::getDocument()`` now
|
||||
throws an ``\InvalidArgumentException`` instead of ``\Exception``, if no
|
||||
``search_identifier`` was provided.
|
||||
throws an ``\InvalidArgumentException`` instead of ``\Exception``, if no
|
||||
``search_identifier`` was provided.
|
||||
|
||||
* ``Codappix\SearchCore\Connection\Elasticsearch\IndexFactory::getIndex()`` now
|
||||
throws an ``\InvalidArgumentException`` if the index does not exist. Leaving
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Codappix\Tests\Unit\Controller;
|
|||
|
||||
use Codappix\SearchCore\Controller\SearchController;
|
||||
use Codappix\SearchCore\Domain\Model\SearchRequest;
|
||||
use Codappix\SearchCore\Domain\Search\CachedSearchService;
|
||||
use Codappix\SearchCore\Domain\Search\SearchService;
|
||||
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
|
||||
use TYPO3\CMS\Extbase\Mvc\Web\Request;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
@ -55,7 +55,7 @@ class SearchControllerTest extends AbstractUnitTestCase
|
|||
|
||||
parent::setUp();
|
||||
|
||||
$searchService = $this->getMockBuilder(CachedSearchService::class)
|
||||
$searchService = $this->getMockBuilder(SearchService::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->request = new Request();
|
||||
|
|
|
@ -58,14 +58,12 @@
|
|||
(isset($configuration['disable.']['elasticsearch']) &&
|
||||
filter_var($configuration['disable.']['elasticsearch'], FILTER_VALIDATE_BOOLEAN) === false)
|
||||
) {
|
||||
$container = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class);
|
||||
$container = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
|
||||
\TYPO3\CMS\Extbase\Object\Container\Container::class
|
||||
);
|
||||
$container->registerImplementation(
|
||||
\Codappix\SearchCore\Connection\ConnectionInterface::class,
|
||||
\Codappix\SearchCore\Connection\Elasticsearch::class
|
||||
);
|
||||
$container->registerImplementation(
|
||||
\Codappix\SearchCore\Domain\Search\SearchServiceInterface::class,
|
||||
\Codappix\SearchCore\Domain\Search\CachedSearchService::class
|
||||
);
|
||||
}
|
||||
})($_EXTKEY, $_EXTCONF);
|
||||
|
|
Loading…
Reference in a new issue