TASK: Migrate existing 7.6 features

We had some features in 7.6 support which we didn't merge up yet.
Mostly very small bug fixes or more helpful logging and processing of
elasticsearch options.

But also adding images of content elements while indexing pages.
This commit is contained in:
Daniel Siepmann 2018-03-13 11:02:29 +01:00
parent a469f63aa6
commit ba19537f4e
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
3 changed files with 66 additions and 18 deletions

View file

@ -53,7 +53,10 @@ class IndexFactory implements Singleton
$index = $connection->getClient()->getIndex('typo3content');
if ($index->exists() === false) {
$index->create($this->getConfigurationFor($documentType));
$config = $this->getConfigurationFor($documentType);
$this->logger->debug(sprintf('Create index %s.', $documentType), [$documentType, $config]);
$index->create($config);
$this->logger->debug(sprintf('Created index %s.', $documentType), [$documentType]);
}
return $index;
@ -64,9 +67,11 @@ class IndexFactory implements Singleton
try {
$configuration = $this->configuration->get('indexing.' . $documentType . '.index');
if (isset($configuration['analysis']['analyzer'])) {
foreach ($configuration['analysis']['analyzer'] as $key => $analyzer) {
$configuration['analysis']['analyzer'][$key] = $this->prepareAnalyzerConfiguration($analyzer);
foreach (['analyzer', 'filter'] as $optionsToExpand) {
if (isset($configuration['analysis'][$optionsToExpand])) {
foreach ($configuration['analysis'][$optionsToExpand] as $key => $options) {
$configuration['analysis'][$optionsToExpand][$key] = $this->prepareOptions($options);
}
}
}
@ -78,7 +83,7 @@ class IndexFactory implements Singleton
protected function prepareAnalyzerConfiguration(array $analyzer) : array
{
$fieldsToExplode = ['char_filter', 'filter'];
$fieldsToExplode = ['char_filter', 'filter', 'word_list'];
foreach ($fieldsToExplode as $fieldToExplode) {
if (isset($analyzer[$fieldToExplode])) {

View file

@ -34,6 +34,12 @@ class PagesIndexer extends TcaIndexer
*/
protected $contentTableService;
/**
* @var \TYPO3\CMS\Core\Resource\FileRepository
* @inject
*/
protected $fileRepository;
/**
* @param TcaTableService $tcaTableService
* @param TcaTableService $contentTableService
@ -60,28 +66,63 @@ class PagesIndexer extends TcaIndexer
}
}
$record['content'] = $this->fetchContentForPage($record['uid']);
$record['media'] = $this->fetchMediaForPage($record['uid']);
$content = $this->fetchContentForPage($record['uid']);
if ($content !== []) {
$record['content'] = $content['content'];
$record['media'] = array_values(array_unique(array_merge($record['media'], $content['images'])));
}
parent::prepareRecord($record);
}
protected function fetchContentForPage(int $uid) : string
protected function fetchContentForPage(int $uid) : array
{
$contentElements = $this->getQuery($this->contentTableService)->execute()->fetchAll();
if ($contentElements === null) {
$this->logger->debug('No content for page ' . $uid);
return '';
return [];
}
$this->logger->debug('Fetched content for page ' . $uid);
$images = [];
$content = [];
foreach ($contentElements as $contentElement) {
$images = array_merge(
$images,
$this->getContentElementImages($contentElement['uid'])
);
$content[] = $contentElement['bodytext'];
}
return [
// Remove Tags.
// Interpret escaped new lines and special chars.
// Trim, e.g. trailing or leading new lines.
return trim(stripcslashes(strip_tags(implode(' ', $content))));
'content' => trim(stripcslashes(strip_tags(implode(' ', $content)))),
'images' => $images,
];
}
protected function getContentElementImages(int $uidOfContentElement) : array
{
return $this->fetchSysFileReferenceUids($uidOfContentElement, 'tt_content', 'image');
}
protected function fetchMediaForPage(int $uid) : array
{
return $this->fetchSysFileReferenceUids($uid, 'pages', 'media');
}
protected function fetchSysFileReferenceUids(int $uid, string $tablename, string $fieldname) : array
{
$imageRelationUids = [];
$imageRelations = $this->fileRepository->findByRelation($tablename, $fieldname, $uid);
foreach ($imageRelations as $relation) {
$imageRelationUids[] = $relation->getUid();
}
return $imageRelationUids;
}
}

View file

@ -136,6 +136,7 @@ class QueryFactory
];
}
if (!empty($boostQueryParts)) {
$query = ArrayUtility::arrayMergeRecursiveOverrule($query, [
'query' => [
'bool' => [
@ -144,6 +145,7 @@ class QueryFactory
],
]);
}
}
protected function addFactorBoost(array &$query)
{