FEATURE: Split configuration to support the concepts

* Add a further level in configurations to support multiple connections
  and indexer.

Relates: #31
This commit is contained in:
Daniel Siepmann 2016-12-20 10:04:44 +01:00
parent 8441dcdff2
commit 5989b65ae0
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
13 changed files with 110 additions and 76 deletions

View file

@ -57,7 +57,7 @@ class IndexCommandController extends CommandController
{ {
// TODO: Allow to index multiple tables at once? // TODO: Allow to index multiple tables at once?
// TODO: Also allow to index everything? // TODO: Also allow to index everything?
if (! in_array($table, GeneralUtility::trimExplode(',', $this->configuration->get('index', 'allowedTables')))) { if (! in_array($table, GeneralUtility::trimExplode(',', $this->configuration->get('indexer.tca.allowedTables')))) {
$this->outputLine('Table is not allowed for indexing.'); $this->outputLine('Table is not allowed for indexing.');
$this->quit(1); $this->quit(1);
} }

View file

@ -21,6 +21,7 @@ namespace Leonmrni\SearchCore\Configuration;
*/ */
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Utility\ArrayUtility;
/** /**
* Container of all configurations for extension. * Container of all configurations for extension.
@ -29,14 +30,14 @@ use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
class ConfigurationContainer implements ConfigurationContainerInterface class ConfigurationContainer implements ConfigurationContainerInterface
{ {
/** /**
* Plaint TypoScript array from extbase for extension / plugin. * Plain TypoScript array from extbase for extension / plugin.
* *
* @var array * @var array
*/ */
protected $settings; protected $settings;
/** /**
* Inject news settings via ConfigurationManager. * Inject settings via ConfigurationManager.
* *
* @param ConfigurationManagerInterface $configurationManager * @param ConfigurationManagerInterface $configurationManager
*/ */
@ -50,34 +51,30 @@ class ConfigurationContainer implements ConfigurationContainerInterface
} }
/** /**
* @param string $section * @param string $path In dot notation.
* @param string $key
* @return mixed * @return mixed
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function get($section, $key) public function get($path)
{ {
if (!isset($this->settings[$section]) || !isset($this->settings[$section][$key])) { $value = ArrayUtility::getValueByPath($this->settings, $path);
if ($value === null) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
'The given configuration option does not exist.', 'The given configuration option "' . $path . '" does not exist.',
InvalidArgumentException::OPTION_DOES_NOT_EXIST InvalidArgumentException::OPTION_DOES_NOT_EXIST
); );
} }
return $this->settings[$section][$key]; return $value;
} }
/** /**
* @param string $section * @param string $path In dot notation.
* @param string $key * @return mixed
* @return mixed|null
*/ */
public function getIfExists($section, $key) public function getIfExists($path)
{ {
try { return ArrayUtility::getValueByPath($this->settings, $path);
return $this->get($section, $key);
} catch (InvalidArgumentException $e) {
return null;
}
} }
} }

View file

@ -30,20 +30,18 @@ interface ConfigurationContainerInterface extends Singleton
{ {
/** /**
* Returns the option defined by section and key. * Returns the option defined by section and key.
* May throw an exception if it's not set. * May throw an exception if it's not set or is null.
* *
* @param string $section * @param string $path In dot notation. E.g. indexer.tca.allowedTables
* @param string $key
* @return mixed * @return mixed
*/ */
public function get($section, $key); public function get($path);
/** /**
* Same as get but will not throw an exception but return null. * Same as get but will not throw an exception but return null.
* *
* @param string $section * @param string $path In dot notation.
* @param string $key
* @return mixed|null * @return mixed|null
*/ */
public function getIfExists($section, $key); public function getIfExists($path);
} }

View file

@ -54,8 +54,8 @@ class Connection implements Singleton
$this->elasticaClient = $elasticaClient; $this->elasticaClient = $elasticaClient;
if ($this->elasticaClient === null) { if ($this->elasticaClient === null) {
$this->elasticaClient = new \Elastica\Client([ $this->elasticaClient = new \Elastica\Client([
'host' => $this->configuration->get('connection', 'host'), 'host' => $this->configuration->get('connections.elasticsearch.host'),
'port' => $this->configuration->get('connection', 'port'), 'port' => $this->configuration->get('connections.elasticsearch.port'),
// TODO: Make configurable // TODO: Make configurable
// 'log' => 'file', // 'log' => 'file',
]); ]);

View file

@ -151,7 +151,7 @@ class TcaTableService
. ' AND pages.no_search = 0' . ' AND pages.no_search = 0'
; ;
$userDefinedWhere = $this->configuration->getIfExists('index', $this->tableName); $userDefinedWhere = $this->configuration->getIfExists('indexer.tca.' . $this->tableName);
if (is_string($userDefinedWhere)) { if (is_string($userDefinedWhere)) {
$whereClause .= $userDefinedWhere; $whereClause .= $userDefinedWhere;
} }
@ -263,7 +263,7 @@ class TcaTableService
*/ */
protected function isBlackListedRootLineConfigured() protected function isBlackListedRootLineConfigured()
{ {
return (bool) $this->configuration->getIfExists('index', 'rootLineBlacklist'); return (bool) $this->configuration->getIfExists('indexer.tca.rootLineBlacklist');
} }
/** /**
@ -273,6 +273,6 @@ class TcaTableService
*/ */
protected function getBlackListedRootLine() protected function getBlackListedRootLine()
{ {
return GeneralUtility::intExplode(',', $this->configuration->getIfExists('index', 'rootLineBlacklist')); return GeneralUtility::intExplode(',', $this->configuration->getIfExists('indexer.tca.rootLineBlacklist'));
} }
} }

View file

@ -86,7 +86,7 @@ class DataHandler implements Singleton
*/ */
public function getAllowedTablesForIndexing() public function getAllowedTablesForIndexing()
{ {
return GeneralUtility::trimExplode(',', $this->configuration->get('index', 'allowedTables')); return GeneralUtility::trimExplode(',', $this->configuration->get('indexer.tca.allowedTables'));
} }
/** /**

View file

@ -1,12 +1,15 @@
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
connection { connections {
elasticsearch {
host = localhost host = localhost
port = 9200 port = 9200
} }
}
index { indexer {
tca {
# Pages are not supported yet, see # Pages are not supported yet, see
# https://github.com/DanielSiepmann/search_core/issues/24 but # https://github.com/DanielSiepmann/search_core/issues/24 but
# should also be added, together with additionalWhereClause # should also be added, together with additionalWhereClause
@ -19,6 +22,7 @@ plugin {
} }
} }
} }
}
} }
module.tx_searchcore < plugin.tx_searchcore module.tx_searchcore < plugin.tx_searchcore

View file

@ -34,34 +34,35 @@ Here is the example default configuration that's provided through static setup:
Options Options
------- -------
The following section contain the different options for e.g. The following section contains the different options, e.g. for :ref:`connections` and
``plugin.tx_searchcore.settings.connection`` or ``plugin.tx_searchcore.settings.index``. :ref:`indexer`: ``plugin.tx_searchcore.settings.connection`` or
``plugin.tx_searchcore.settings.index``.
.. warning::
The structure will change as we need to support multiple indexer and connections.
The options will stay the same.
For further information take a look at :issue:`31`.
.. _configuration_options_connection: .. _configuration_options_connection:
connection connections
^^^^^^^^^^ ^^^^^^^^^^^
Holds settings regarding the connection to search service like Elasticsearch or Solr. Holds settings regarding the different possible connections for search services like Elasticsearch
or Solr.
Configured as:: Configured as::
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
connection { connections {
connectionName {
// the settings // the settings
} }
} }
} }
} }
}
Where ``connectionName`` is one of the available :ref:`connections`.
The following settings are available. For each setting its documented which connection consumes it.
.. _host: .. _host:
@ -75,7 +76,7 @@ Configured as::
Example:: Example::
plugin.tx_searchcore.settings.connection.host = localhost plugin.tx_searchcore.settings.connections.elasticsearch.host = localhost
.. _port: .. _port:
@ -88,7 +89,7 @@ Configured as::
Example:: Example::
plugin.tx_searchcore.settings.connection.port = 9200 plugin.tx_searchcore.settings.connections.elasticsearch.port = 9200
.. _configuration_options_index: .. _configuration_options_index:
@ -96,19 +97,25 @@ Configured as::
index index
^^^^^ ^^^^^
Holds settings regarding the indexing of TYPO3 records to search service. Holds settings regarding the indexing, e.g. of TYPO3 records, to search services.
Configured as:: Configured as::
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
index { indexer {
indexerName {
// the settings // the settings
} }
} }
} }
} }
}
Where ``indexerName`` is one of the available :ref:`indexer`.
The following settings are available. For each setting its documented which indexer consumes it.
.. _allowedTables: .. _allowedTables:
@ -124,7 +131,7 @@ Configured as::
Example:: Example::
plugin.tx_searchcore.settings.index.allowedTables = tt_content, fe_users plugin.tx_searchcore.settings.indexer.tca.allowedTables = tt_content, fe_users
.. _rootLineBlacklist: .. _rootLineBlacklist:
@ -142,7 +149,7 @@ Configured as::
Example:: Example::
plugin.tx_searchcore.settings.index.rootLineBlacklist = 3, 10, 100 plugin.tx_searchcore.settings.index.tca.rootLineBlacklist = 3, 10, 100
Also it's possible to define some behaviour for the different document types. In context of TYPO3 Also it's possible to define some behaviour for the different document types. In context of TYPO3
tables are used as document types 1:1. It's possible to configure different tables. The following tables are used as document types 1:1. It's possible to configure different tables. The following
@ -161,7 +168,7 @@ options are available:
Example:: Example::
plugin.tx_searchcore.settings.index.tt_content.additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu') plugin.tx_searchcore.settings.index.tca.tt_content.additionalWhereClause = tt_content.CType NOT IN ('gridelements_pi1', 'list', 'div', 'menu')
.. attention:: .. attention::

View file

@ -1,3 +1,5 @@
.. highlight:: bash
.. _contribution: .. _contribution:
Contribution Contribution
@ -7,6 +9,22 @@ Everyone is welcome to contribute, whether it's code, issues, feature requests o
Below is a documentation what to respect during contributions. Below is a documentation what to respect during contributions.
.. _contribution_setup:
Setup
-----
To start contributions regarding code, make sure to setup your system::
git clone git@github.com:DanielSiepmann/search_core.git \
&& cd search_core \
&& make install \
&& make functionalTests
If all tests are okay, start your work.
Of course you might need some requirements like running elasticsearch and composer to work before.
.. _contribution_development: .. _contribution_development:
Development Development

View file

@ -1,16 +1,20 @@
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
connection { connections {
elasticsearch {
host = localhost host = localhost
port = 9200 port = 9200
} }
}
index { indexer {
tca {
allowedTables = tt_content allowedTables = tt_content
} }
} }
} }
}
} }
module.tx_searchcore < plugin.tx_searchcore module.tx_searchcore < plugin.tx_searchcore

View file

@ -1,11 +1,13 @@
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
index { indexer {
tca {
allowedTables = tt_content, fe_user allowedTables = tt_content, fe_user
} }
} }
} }
}
} }
module.tx_searchcore < plugin.tx_searchcore module.tx_searchcore < plugin.tx_searchcore

View file

@ -1,11 +1,13 @@
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
index { indexer {
tca {
rootLineBlacklist = 3 rootLineBlacklist = 3
} }
} }
} }
}
} }
module.tx_searchcore < plugin.tx_searchcore module.tx_searchcore < plugin.tx_searchcore

View file

@ -1,13 +1,15 @@
plugin { plugin {
tx_searchcore { tx_searchcore {
settings { settings {
index { indexer {
tca {
tt_content { tt_content {
additionalWhereClause = tt_content.CType NOT IN ('div') additionalWhereClause = tt_content.CType NOT IN ('div')
} }
} }
} }
} }
}
} }
module.tx_searchcore < plugin.tx_searchcore module.tx_searchcore < plugin.tx_searchcore