Merge pull request #110 from Codappix/feature/75-make-index-configurable

FEATURE: Provide new feature to configure the index
This commit is contained in:
Daniel Siepmann 2018-05-18 10:37:02 +02:00 committed by GitHub
commit 664cc92152
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 71 additions and 7 deletions

View file

@ -161,10 +161,13 @@ class Elasticsearch implements Singleton, ConnectionInterface
public function deleteIndex(string $documentType)
{
$index = $this->connection->getClient()->getIndex('typo3content');
$index = $this->connection->getClient()->getIndex($this->indexFactory->getIndexName());
if (! $index->exists()) {
$this->logger->notice('Index did not exist, therefore was not deleted.', [$documentType, 'typo3content']);
$this->logger->notice(
'Index did not exist, therefore was not deleted.',
[$documentType, $this->indexFactory->getIndexName()]
);
return;
}
@ -193,7 +196,7 @@ class Elasticsearch implements Singleton, ConnectionInterface
$this->logger->debug('Search for', [$searchRequest->getSearchTerm()]);
$search = new \Elastica\Search($this->connection->getClient());
$search->addIndex('typo3content');
$search->addIndex($this->indexFactory->getIndexName());
$search->setQuery($this->queryFactory->create($searchRequest));
return $this->objectManager->get(SearchResult::class, $searchRequest, $search->search());

View file

@ -60,12 +60,22 @@ class IndexFactory implements Singleton
$this->configuration = $configuration;
}
/**
* Get the index name from the typoscript settings.
*
* @return string
*/
public function getIndexName()
{
return $this->configuration->get('connections.elasticsearch.index');
}
/**
* Get an index bases on TYPO3 table name.
*/
public function getIndex(Connection $connection, string $documentType) : \Elastica\Index
{
$index = $connection->getClient()->getIndex('typo3content');
$index = $connection->getClient()->getIndex($this->getIndexName());
if ($index->exists() === false) {
$config = $this->getConfigurationFor($documentType);

View file

@ -5,6 +5,7 @@ plugin {
elasticsearch {
host = localhost
port = 9200
index = typo3content
}
}

View file

@ -5,6 +5,7 @@ plugin {
elasticsearch {
host = {$plugin.tx_searchcore.settings.connections.elasticsearch.host}
port = {$plugin.tx_searchcore.settings.connections.elasticsearch.port}
index = {$plugin.tx_searchcore.settings.connections.elasticsearch.index}
}
}

View file

@ -5,6 +5,7 @@ Changelog
:maxdepth: 1
:glob:
changelog/20180518-75-make-index-name-configurable
changelog/20180424-149-extract-relation-resolver-to-data-processing
changelog/20180410-148-keep-sys_language_uid
changelog/20180315-134-make-conent-fields-configurable

View file

@ -0,0 +1,11 @@
Feature 75 "Make index name configurable"
==========================================
Prior to the change the index name was not changeable and hardcoded to `typo3content`.
Now you can change the index name for different use cases.
You can now use one Elasticsearch server for multiple TYPO3 installations or multiple environments.
The default is set to `typo3content`. No changes are necessary.
See :issue:`75`.

View file

@ -46,3 +46,18 @@ The port where search service is reachable. E.g. default ``9200`` for Elasticsea
Example::
plugin.tx_searchcore.settings.connections.elasticsearch.port = 9200
.. _index:
``index``
---------
Used by: :ref:`connection_elasticsearch`.
The index where the documents are being indexed to. E.g. default ``typo3content`` for Elasticsearch.
This can be used to have one Elasticsearch server for multiple environments. E.g. production and staging.
Example::
plugin.tx_searchcore.settings.connections.elasticsearch.index = typo3content

View file

@ -5,6 +5,7 @@ plugin {
elasticsearch {
host = localhost
port = 9200
index = typo3content
}
}

View file

@ -24,6 +24,7 @@ use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
use Codappix\SearchCore\Connection\Elasticsearch\Connection;
use Codappix\SearchCore\Connection\Elasticsearch\IndexFactory;
use Codappix\SearchCore\Tests\Unit\AbstractUnitTestCase;
use PHPUnit_Framework_MockObject_MockObject;
class IndexFactoryTest extends AbstractUnitTestCase
{
@ -32,6 +33,11 @@ class IndexFactoryTest extends AbstractUnitTestCase
*/
protected $subject;
/**
* @var PHPUnit_Framework_MockObject_MockObject
*/
protected $configuration;
public function setUp()
{
parent::setUp();
@ -68,6 +74,11 @@ class IndexFactoryTest extends AbstractUnitTestCase
->method('getClient')
->willReturn($clientMock);
$this->configuration->expects($this->once())
->method('get')
->with('connections.elasticsearch.index')
->willReturn('typo3content');
$this->subject->getIndex($connection, 'someIndex');
}
@ -123,10 +134,20 @@ class IndexFactoryTest extends AbstractUnitTestCase
->method('getClient')
->willReturn($clientMock);
$this->configuration->expects($this->once())
$this->configuration->expects($this->exactly(2))
->method('get')
->with('indexing.someIndex.index')
->willReturn($configuration);
->will(
$this->returnValueMap([
[
'indexing.someIndex.index',
$configuration
],
[
'connections.elasticsearch.index',
'typo3content'
]
])
);
$this->subject->getIndex($connection, 'someIndex');
}