mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-27 01:36:12 +01:00
[FEATURE] Use interface for SearchService
Added cached proxy service for data interaction
This commit is contained in:
parent
b8d708874e
commit
ef43bc1674
5 changed files with 58 additions and 20 deletions
|
@ -22,7 +22,7 @@ namespace Codappix\SearchCore\Controller;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Codappix\SearchCore\Domain\Model\SearchRequest;
|
use Codappix\SearchCore\Domain\Model\SearchRequest;
|
||||||
use Codappix\SearchCore\Domain\Search\CachedSearchService;
|
use Codappix\SearchCore\Domain\Search\SearchServiceInterface;
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,21 +31,24 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
|
||||||
class SearchController extends ActionController
|
class SearchController extends ActionController
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var CachedSearchService
|
* @var SearchServiceInterface
|
||||||
*/
|
*/
|
||||||
protected $searchService;
|
protected $searchService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param CachedSearchService $searchService
|
* @param SearchServiceInterface $searchService
|
||||||
*/
|
*/
|
||||||
public function __construct(CachedSearchService $searchService)
|
public function __construct(SearchServiceInterface $searchService)
|
||||||
{
|
{
|
||||||
$this->searchService = $searchService;
|
$this->searchService = $searchService;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initializeSearchAction()
|
/**
|
||||||
|
* Allow dynamic properties in search request
|
||||||
|
*/
|
||||||
|
public function initializeResultsAction()
|
||||||
{
|
{
|
||||||
if (isset($this->settings['searching']['mode'])
|
if (isset($this->settings['searching']['mode'])
|
||||||
&& $this->settings['searching']['mode'] === 'filter'
|
&& $this->settings['searching']['mode'] === 'filter'
|
||||||
|
@ -63,23 +66,10 @@ class SearchController extends ActionController
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display results and deliver original request and result to view.
|
|
||||||
*/
|
|
||||||
public function formAction(SearchRequest $searchRequest = null)
|
|
||||||
{
|
|
||||||
$this->action($searchRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display results and deliver original request and result to view.
|
* Display results and deliver original request and result to view.
|
||||||
*/
|
*/
|
||||||
public function resultsAction(SearchRequest $searchRequest = null)
|
public function resultsAction(SearchRequest $searchRequest = null)
|
||||||
{
|
|
||||||
$this->action($searchRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function action(SearchRequest $searchRequest = null)
|
|
||||||
{
|
{
|
||||||
$searchResult = null;
|
$searchResult = null;
|
||||||
if ($searchRequest !== null) {
|
if ($searchRequest !== null) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ use TYPO3\CMS\Core\SingletonInterface;
|
||||||
* Service: Cached Search
|
* Service: Cached Search
|
||||||
* @package Codappix\SearchCore\Domain\Search
|
* @package Codappix\SearchCore\Domain\Search
|
||||||
*/
|
*/
|
||||||
class CachedSearchService implements SingletonInterface
|
class CachedSearchService implements SingletonInterface, SearchServiceInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
|
@ -55,6 +55,11 @@ class CachedSearchService implements SingletonInterface
|
||||||
return $this->results[$hash] = $this->searchService->search($searchRequest);
|
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
|
protected function getHash(SearchRequestInterface $searchRequest): string
|
||||||
{
|
{
|
||||||
if (is_callable([$searchRequest, 'getRequestHash'])) {
|
if (is_callable([$searchRequest, 'getRequestHash'])) {
|
||||||
|
|
|
@ -35,7 +35,7 @@ use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||||
/**
|
/**
|
||||||
* Service to process a search request.
|
* Service to process a search request.
|
||||||
*/
|
*/
|
||||||
class SearchService
|
class SearchService implements SearchServiceInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var ConnectionInterface
|
* @var ConnectionInterface
|
||||||
|
|
39
Classes/Domain/Search/SearchServiceInterface.php
Normal file
39
Classes/Domain/Search/SearchServiceInterface.php
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service to process a search request.
|
||||||
|
*/
|
||||||
|
interface SearchServiceInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function search(SearchRequestInterface $searchRequest): SearchResultInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes the result, e.g. applies configured data processing to result.
|
||||||
|
*/
|
||||||
|
public function processResult(SearchResultInterface $searchResult): SearchResultInterface;
|
||||||
|
}
|
|
@ -62,5 +62,9 @@ call_user_func(function ($extension, $configuration) {
|
||||||
\Codappix\SearchCore\Connection\ConnectionInterface::class,
|
\Codappix\SearchCore\Connection\ConnectionInterface::class,
|
||||||
\Codappix\SearchCore\Connection\Elasticsearch::class
|
\Codappix\SearchCore\Connection\Elasticsearch::class
|
||||||
);
|
);
|
||||||
|
$container->registerImplementation(
|
||||||
|
\Codappix\SearchCore\Domain\Search\SearchServiceInterface::class,
|
||||||
|
\Codappix\SearchCore\Domain\Search\CachedSearchService::class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}, $_EXTKEY, $_EXTCONF);
|
}, $_EXTKEY, $_EXTCONF);
|
||||||
|
|
Loading…
Reference in a new issue