mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-26 07:16:11 +01:00
Merge branch 'feature/update-9' of github.com:bergwerk/search_core into feature/update-9
# Conflicts: # Classes/Configuration/ConfigurationContainer.php
This commit is contained in:
commit
6a697133bb
4 changed files with 80 additions and 50 deletions
|
@ -23,6 +23,7 @@ namespace Codappix\SearchCore\Configuration;
|
||||||
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
|
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
|
||||||
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
|
||||||
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
use TYPO3\CMS\Core\Utility\ArrayUtility;
|
||||||
|
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container of all configurations for extension.
|
* Container of all configurations for extension.
|
||||||
|
@ -61,12 +62,9 @@ class ConfigurationContainer implements ConfigurationContainerInterface
|
||||||
*/
|
*/
|
||||||
public function get(string $path)
|
public function get(string $path)
|
||||||
{
|
{
|
||||||
try
|
$value = ArrayUtility::getValueByPath($this->settings, $path, '.');
|
||||||
{
|
|
||||||
return ArrayUtility::getValueByPath($this->settings, $path);
|
if ($value === null) {
|
||||||
}
|
|
||||||
catch (MissingArrayPathException $exception)
|
|
||||||
{
|
|
||||||
throw new InvalidArgumentException(
|
throw new InvalidArgumentException(
|
||||||
'The given configuration option "' . $path . '" does not exist.',
|
'The given configuration option "' . $path . '" does not exist.',
|
||||||
InvalidArgumentException::OPTION_DOES_NOT_EXIST
|
InvalidArgumentException::OPTION_DOES_NOT_EXIST
|
||||||
|
@ -82,7 +80,7 @@ class ConfigurationContainer implements ConfigurationContainerInterface
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return ArrayUtility::getValueByPath($this->settings, $path);
|
return ArrayUtility::getValueByPath($this->settings, $path, '.');
|
||||||
}
|
}
|
||||||
catch (\Exception $exception)
|
catch (\Exception $exception)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Codappix\SearchCore\Domain\Index;
|
namespace Codappix\SearchCore\Domain\Index;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -23,6 +24,8 @@ namespace Codappix\SearchCore\Domain\Index;
|
||||||
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
use Codappix\SearchCore\Configuration\ConfigurationContainerInterface;
|
||||||
use Codappix\SearchCore\Configuration\InvalidArgumentException;
|
use Codappix\SearchCore\Configuration\InvalidArgumentException;
|
||||||
use Codappix\SearchCore\Connection\ConnectionInterface;
|
use Codappix\SearchCore\Connection\ConnectionInterface;
|
||||||
|
use TYPO3\CMS\Core\Exception;
|
||||||
|
use TYPO3\CMS\Core\Utility\Exception\MissingArrayPathException;
|
||||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||||
|
|
||||||
abstract class AbstractIndexer implements IndexerInterface
|
abstract class AbstractIndexer implements IndexerInterface
|
||||||
|
@ -31,28 +34,28 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
* @var ConnectionInterface
|
* @var ConnectionInterface
|
||||||
*/
|
*/
|
||||||
protected $connection;
|
protected $connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ConfigurationContainerInterface
|
* @var ConfigurationContainerInterface
|
||||||
*/
|
*/
|
||||||
protected $configuration;
|
protected $configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $identifier = '';
|
protected $identifier = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Codappix\SearchCore\DataProcessing\Service
|
* @var \Codappix\SearchCore\DataProcessing\Service
|
||||||
* @inject
|
* @inject
|
||||||
*/
|
*/
|
||||||
protected $dataProcessorService;
|
protected $dataProcessorService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \TYPO3\CMS\Core\Log\Logger
|
* @var \TYPO3\CMS\Core\Log\Logger
|
||||||
*/
|
*/
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inject log manager to get concrete logger from it.
|
* Inject log manager to get concrete logger from it.
|
||||||
*
|
*
|
||||||
|
@ -62,18 +65,18 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
{
|
{
|
||||||
$this->logger = $logManager->getLogger(__CLASS__);
|
$this->logger = $logManager->getLogger(__CLASS__);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setIdentifier(string $identifier)
|
public function setIdentifier(string $identifier)
|
||||||
{
|
{
|
||||||
$this->identifier = $identifier;
|
$this->identifier = $identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(ConnectionInterface $connection, ConfigurationContainerInterface $configuration)
|
public function __construct(ConnectionInterface $connection, ConfigurationContainerInterface $configuration)
|
||||||
{
|
{
|
||||||
$this->connection = $connection;
|
$this->connection = $connection;
|
||||||
$this->configuration = $configuration;
|
$this->configuration = $configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAllDocuments()
|
public function indexAllDocuments()
|
||||||
{
|
{
|
||||||
$this->logger->info('Start indexing');
|
$this->logger->info('Start indexing');
|
||||||
|
@ -81,24 +84,24 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
if ($records === null) {
|
if ($records === null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($records as &$record) {
|
foreach ($records as &$record) {
|
||||||
$this->prepareRecord($record);
|
$this->prepareRecord($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->debug('Index records.', [$records]);
|
$this->logger->debug('Index records.', [$records]);
|
||||||
$this->connection->addDocuments($this->getDocumentName(), $records);
|
$this->connection->addDocuments($this->getDocumentName(), $records);
|
||||||
}
|
}
|
||||||
$this->logger->info('Finish indexing');
|
$this->logger->info('Finish indexing');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexDocument(string $identifier)
|
public function indexDocument(string $identifier)
|
||||||
{
|
{
|
||||||
$this->logger->info('Start indexing single record.', [$identifier]);
|
$this->logger->info('Start indexing single record.', [$identifier]);
|
||||||
try {
|
try {
|
||||||
$record = $this->getRecord((int) $identifier);
|
$record = $this->getRecord((int)$identifier);
|
||||||
$this->prepareRecord($record);
|
$this->prepareRecord($record);
|
||||||
|
|
||||||
$this->connection->addDocument($this->getDocumentName(), $record);
|
$this->connection->addDocument($this->getDocumentName(), $record);
|
||||||
} catch (NoRecordFoundException $e) {
|
} catch (NoRecordFoundException $e) {
|
||||||
$this->logger->info('Could not index document. Try to delete it therefore.', [$e->getMessage()]);
|
$this->logger->info('Could not index document. Try to delete it therefore.', [$e->getMessage()]);
|
||||||
|
@ -106,47 +109,70 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
}
|
}
|
||||||
$this->logger->info('Finish indexing');
|
$this->logger->info('Finish indexing');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$this->logger->info('Start deletion of index.');
|
$this->logger->info('Start deletion of index.');
|
||||||
$this->connection->deleteIndex($this->getDocumentName());
|
$this->connection->deleteIndex($this->getDocumentName());
|
||||||
$this->logger->info('Finish deletion.');
|
$this->logger->info('Finish deletion.');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRecordGenerator() : \Generator
|
protected function getRecordGenerator(): \Generator
|
||||||
{
|
{
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
$limit = $this->getLimit();
|
$limit = $this->getLimit();
|
||||||
|
|
||||||
while (($records = $this->getRecords($offset, $limit)) !== []) {
|
while (($records = $this->getRecords($offset, $limit)) !== []) {
|
||||||
yield $records;
|
yield $records;
|
||||||
$offset += $limit;
|
$offset += $limit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $record
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
protected function prepareRecord(array &$record)
|
protected function prepareRecord(array &$record)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
foreach ($this->configuration->get('indexing.' . $this->identifier . '.dataProcessing') as $configuration) {
|
$indexingConfiguration = $this->configuration->get('indexing.' . $this->identifier . '.dataProcessing');
|
||||||
$record = $this->dataProcessorService->executeDataProcessor($configuration, $record, $this->identifier);
|
|
||||||
|
if (!empty($indexingConfiguration) && is_array($indexingConfiguration)) {
|
||||||
|
foreach ($indexingConfiguration as $configuration) {
|
||||||
|
$record = $this->dataProcessorService->executeDataProcessor($configuration, $record,
|
||||||
|
$this->identifier);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
if ($e instanceof InvalidArgumentException) {
|
||||||
|
// Nothing to do
|
||||||
|
} elseif ($e instanceof MissingArrayPathException) {
|
||||||
|
// Nothing to do
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
} catch (InvalidArgumentException $e) {
|
|
||||||
// Nothing to do.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->handleAbstract($record);
|
$this->handleAbstract($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $record
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*/
|
||||||
protected function handleAbstract(array &$record)
|
protected function handleAbstract(array &$record)
|
||||||
{
|
{
|
||||||
$record['search_abstract'] = '';
|
$record['search_abstract'] = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$fieldsToUse = GeneralUtility::trimExplode(
|
|
||||||
',',
|
$indexConfiguration = $this->configuration->get('indexing.' . $this->identifier . '.abstractFields');
|
||||||
$this->configuration->get('indexing.' . $this->identifier . '.abstractFields')
|
|
||||||
);
|
$fieldsToUse = GeneralUtility::trimExplode(',', $indexConfiguration);
|
||||||
if ($fieldsToUse === []) {
|
if ($fieldsToUse === []) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -156,29 +182,35 @@ abstract class AbstractIndexer implements IndexerInterface
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (InvalidArgumentException $e) {
|
} catch (\Exception $e) {
|
||||||
return;
|
if ($e instanceof InvalidArgumentException) {
|
||||||
|
return;
|
||||||
|
} elseif ($e instanceof MissingArrayPathException) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the limit to use to fetch records.
|
* Returns the limit to use to fetch records.
|
||||||
*/
|
*/
|
||||||
protected function getLimit() : int
|
protected function getLimit(): int
|
||||||
{
|
{
|
||||||
// TODO: Make configurable.
|
// TODO: Make configurable.
|
||||||
return 50;
|
return 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
abstract protected function getRecords(int $offset, int $limit);
|
abstract protected function getRecords(int $offset, int $limit);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws NoRecordFoundException If record could not be found.
|
* @throws NoRecordFoundException If record could not be found.
|
||||||
*/
|
*/
|
||||||
abstract protected function getRecord(int $identifier) : array;
|
abstract protected function getRecord(int $identifier): array;
|
||||||
|
|
||||||
abstract protected function getDocumentName() : string;
|
abstract protected function getDocumentName(): string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,7 @@
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.0.0",
|
"php": ">=7.0.0",
|
||||||
"typo3/cms-core": ">= 7.6.0 < 10.0.0",
|
"typo3/cms-core": ">= 7.6.0 < 10.0.0",
|
||||||
"ruflin/elastica": "~3.2",
|
"ruflin/elastica": "~3.2"
|
||||||
"friendsoftypo3/typo3db-legacy": "^1.1.1"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~6.4.4",
|
"phpunit/phpunit": "~6.4.4",
|
||||||
|
|
|
@ -42,12 +42,13 @@ call_user_func(
|
||||||
|
|
||||||
\Codappix\SearchCore\Compatibility\ImplementationRegistrationService::registerImplementations();
|
\Codappix\SearchCore\Compatibility\ImplementationRegistrationService::registerImplementations();
|
||||||
|
|
||||||
|
|
||||||
// API does make use of object manager, therefore use GLOBALS
|
// API does make use of object manager, therefore use GLOBALS
|
||||||
$extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get($extensionKey);
|
$extensionConfiguration = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class)->get($extensionKey);
|
||||||
|
|
||||||
if ($extensionConfiguration === false
|
if ($extensionConfiguration === false
|
||||||
|| !isset($extensionConfiguration['disable.']['elasticsearch'])
|
|| !isset($extensionConfiguration['disable']['elasticsearch'])
|
||||||
|| $extensionConfiguration['disable.']['elasticsearch'] !== '1'
|
|| $extensionConfiguration['disable']['elasticsearch'] !== '1'
|
||||||
) {
|
) {
|
||||||
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
|
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\Container\Container::class)
|
||||||
->registerImplementation(
|
->registerImplementation(
|
||||||
|
|
Loading…
Reference in a new issue