From ab1b6b5da9c67d6c028790ee25286d053fbf9713 Mon Sep 17 00:00:00 2001 From: Benjamin Serfhos Date: Mon, 29 Oct 2018 09:52:18 +0100 Subject: [PATCH] [TASK] Finetune so interface is not reliant for Elastica library --- Classes/Connection/ConnectionInterface.php | 12 +++++------- Classes/Connection/Elasticsearch.php | 12 ++++++++++++ Classes/Domain/Index/AbstractIndexer.php | 9 +-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Classes/Connection/ConnectionInterface.php b/Classes/Connection/ConnectionInterface.php index 9480d04..76122f8 100644 --- a/Classes/Connection/ConnectionInterface.php +++ b/Classes/Connection/ConnectionInterface.php @@ -21,8 +21,6 @@ namespace Codappix\SearchCore\Connection; * 02110-1301, USA. */ -use Elastica\Query; - /** * Defines interface for connections to storage backend for interacting with documents. */ @@ -57,13 +55,13 @@ interface ConnectionInterface */ public function search(SearchRequestInterface $searchRequest): SearchResultInterface; + /** + * Will delete the index / db of defined document type. + */ + public function deleteIndexByDocumentType(string $documentType); + /** * Will delete the whole index / db. */ public function deleteIndex(); - - /** - * Will delete the index / db of defined document type. - */ - public function deleteIndexByQuery(Query $query); } diff --git a/Classes/Connection/Elasticsearch.php b/Classes/Connection/Elasticsearch.php index b77253b..c7e8504 100644 --- a/Classes/Connection/Elasticsearch.php +++ b/Classes/Connection/Elasticsearch.php @@ -176,6 +176,18 @@ class Elasticsearch implements Singleton, ConnectionInterface $index->delete(); } + public function deleteIndexByDocumentType(string $documentType) + { + $query = Query::create([ + 'query' => [ + 'term' => [ + 'search_document_type' => $documentType + ] + ] + ]); + $this->deleteIndexByQuery($query); + } + public function deleteIndexByQuery(Query $query) { $index = $this->connection->getClient()->getIndex($this->indexFactory->getIndexName()); diff --git a/Classes/Domain/Index/AbstractIndexer.php b/Classes/Domain/Index/AbstractIndexer.php index a016de0..797bbb2 100644 --- a/Classes/Domain/Index/AbstractIndexer.php +++ b/Classes/Domain/Index/AbstractIndexer.php @@ -24,7 +24,6 @@ namespace Codappix\SearchCore\Domain\Index; use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; use Codappix\SearchCore\Configuration\InvalidArgumentException; use Codappix\SearchCore\Connection\ConnectionInterface; -use Elastica\Query; use TYPO3\CMS\Core\Utility\GeneralUtility; abstract class AbstractIndexer implements IndexerInterface @@ -114,13 +113,7 @@ abstract class AbstractIndexer implements IndexerInterface public function deleteDocuments() { $this->logger->info('Start deletion of indexed documents.'); - $this->connection->deleteIndexByQuery(Query::create([ - 'query' => [ - 'term' => [ - 'search_document_type' => $this->getDocumentName() - ] - ] - ])); + $this->connection->deleteIndexByDocumentType($this->getDocumentName()); $this->logger->info('Finish deletion.'); }