This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d89e616
commit b079dd8
Showing
28 changed files
with
1,355 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
namespace Leonmrni\SearchCore\Connection; | ||
|
||
/* | ||
* Copyright (C) 2016 Daniel Siepmann <[email protected]> | ||
* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* Defines interface for connections to storage backend for interacting with documents. | ||
*/ | ||
interface ConnectionInterface | ||
{ | ||
/** | ||
* Will add a new document, based on his identifier and record type. | ||
* | ||
* @param string $recordType | ||
* @param int $identifier | ||
* @param array $record | ||
* | ||
* @return | ||
*/ | ||
public function add($recordType, $identifier, array $record); | ||
|
||
/** | ||
* Add the given records. | ||
* | ||
* @param string $recordType | ||
* @param array $records | ||
*/ | ||
public function addDocuments($recordType, array $records); | ||
|
||
/** | ||
* Will update an existing document, based on his identifier and record type. | ||
* | ||
* @param string $recordType | ||
* @param int $identifier | ||
* @param array $record | ||
* | ||
* @return | ||
*/ | ||
public function update($recordType, $identifier, array $record); | ||
|
||
/** | ||
* Will remove an existing document, based on his identifier and record type. | ||
* | ||
* @param string $recordType | ||
* @param int $identifier | ||
* | ||
* @return | ||
*/ | ||
public function delete($recordType, $identifier); | ||
|
||
/** | ||
* Search by given request and return result. | ||
* | ||
* @param SearchRequestInterface $searchRequest | ||
* @return SearchResultInterface | ||
*/ | ||
public function search(SearchRequestInterface $searchRequest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<?php | ||
namespace Leonmrni\SearchCore\Connection; | ||
|
||
/* | ||
* Copyright (C) 2016 Daniel Siepmann <[email protected]> | ||
* | ||
* 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 TYPO3\CMS\Core\SingletonInterface as Singleton; | ||
|
||
/** | ||
* Outer wrapper to elasticsearch. | ||
*/ | ||
class Elasticsearch implements Singleton, ConnectionInterface | ||
{ | ||
/** | ||
* @var Elasticsearch\Connection | ||
*/ | ||
protected $connection; | ||
|
||
/** | ||
* @var IndexFactory | ||
*/ | ||
protected $indexFactory; | ||
|
||
/** | ||
* @var TypeFactory | ||
*/ | ||
protected $typeFactory; | ||
|
||
/** | ||
* @var DocumentFactory | ||
*/ | ||
protected $documentFactory; | ||
|
||
/** | ||
* @var \TYPO3\CMS\Core\Log\Logger | ||
*/ | ||
protected $logger; | ||
|
||
/** | ||
* Inject log manager to get concrete logger from it. | ||
* | ||
* @param \TYPO3\CMS\Core\Log\LogManager $logManager | ||
*/ | ||
public function injectLogger(\TYPO3\CMS\Core\Log\LogManager $logManager) | ||
{ | ||
$this->logger = $logManager->getLogger(__CLASS__); | ||
} | ||
|
||
/** | ||
* @param Elasticsearch\Connection $connection | ||
* @param Elasticsearch\IndexFactory $indexFactory | ||
* @param Elasticsearch\TypeFactory $typeFactory | ||
* @param Elasticsearch\DocumentFactory $documentFactory | ||
*/ | ||
public function __construct( | ||
Elasticsearch\Connection $connection, | ||
Elasticsearch\IndexFactory $indexFactory, | ||
Elasticsearch\TypeFactory $typeFactory, | ||
Elasticsearch\DocumentFactory $documentFactory | ||
) { | ||
$this->connection = $connection; | ||
$this->indexFactory = $indexFactory; | ||
$this->typeFactory = $typeFactory; | ||
$this->documentFactory = $documentFactory; | ||
} | ||
|
||
public function add($recordType, $identifier, array $record) | ||
{ | ||
throw new \Exception('Implement', 1481190734); | ||
} | ||
|
||
public function delete($recordType, $identifier) | ||
{ | ||
throw new \Exception('Implement', 1481190734); | ||
} | ||
|
||
public function update($tableName, $identifier, array $record) | ||
{ | ||
$this->addDocument($tableName, $identifier, $record); | ||
} | ||
|
||
protected function addDocument($tableName, $identifier, array $record) | ||
{ | ||
throw new \Exception('Implement', 1481192791); | ||
} | ||
|
||
/** | ||
* Add the given records to elasticsearch. | ||
* | ||
* @param string $tableName | ||
* @param array $records | ||
*/ | ||
public function addDocuments($tableName, array $records) | ||
{ | ||
$type = $this->typeFactory->getType( | ||
$this->indexFactory->getIndex( | ||
$this->connection, | ||
$tableName | ||
), | ||
$tableName | ||
); | ||
|
||
$type->addDocuments( | ||
$this->documentFactory->getDocuments($tableName, $records) | ||
); | ||
|
||
$type->getIndex()->refresh(); | ||
} | ||
|
||
/** | ||
* @param SearchRequestInterface $searchRequest | ||
* @return SearchResultInterface | ||
*/ | ||
public function search(SearchRequestInterface $searchRequest) | ||
{ | ||
$this->logger->debug('Search for', [$searchRequest->getSearchTerm()]); | ||
|
||
$search = new \Elastica\Search($this->connection->getClient()); | ||
$search->addIndex('typo3content'); | ||
|
||
// TODO: Return wrapped result to implement our interface. | ||
return $search->search($searchRequest->getSearchTerm()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
namespace Leonmrni\SearchCore\Connection\Elasticsearch; | ||
|
||
/* | ||
* Copyright (C) 2016 Daniel Siepmann <[email protected]> | ||
* | ||
* 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 TYPO3\CMS\Core\SingletonInterface as Singleton; | ||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; | ||
|
||
/** | ||
* The current connection to elasticsearch. | ||
* | ||
* Wrapper for Elastica\Client. | ||
*/ | ||
class Connection implements Singleton | ||
{ | ||
/** | ||
* @var \Elastica\Client | ||
*/ | ||
protected $elasticaClient; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $settings; | ||
|
||
/** | ||
* @param \Elastica\Client $elasticaClient | ||
*/ | ||
public function __construct(\Elastica\Client $elasticaClient = null) | ||
{ | ||
$this->elasticaClient = $elasticaClient; | ||
} | ||
|
||
/** | ||
* Inject news settings via ConfigurationManager. | ||
* | ||
* TODO: Refactor to configuration object to have a singleton holding the | ||
* settings with validation and propper getter? | ||
* | ||
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager | ||
*/ | ||
public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) | ||
{ | ||
$this->settings = $configurationManager->getConfiguration( | ||
ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS, | ||
'SearchCore', | ||
'search' | ||
); | ||
} | ||
|
||
/** | ||
* Used to configure elasticaClient if no one was injected. Will use | ||
* injected settings for configuration. | ||
*/ | ||
public function initializeObject() | ||
{ | ||
if ($this->elasticaClient === null) { | ||
$this->elasticaClient = new \Elastica\Client([ | ||
'host' => $this->settings['host'], | ||
'port' => $this->settings['port'], | ||
// TODO: Make configurable | ||
// 'log' => 'file', | ||
]); | ||
// TODO: Make configurable. | ||
// new \Elastica\Log($this->elasticaClient); | ||
} | ||
} | ||
|
||
/** | ||
* Get the concrete client for internal usage! | ||
* | ||
* @return \Elastica\Client | ||
*/ | ||
public function getClient() | ||
{ | ||
return $this->elasticaClient; | ||
} | ||
} |
Oops, something went wrong.