mirror of
https://github.com/Codappix/search_core.git
synced 2024-11-22 04:16:12 +01:00
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:
parent
a469f63aa6
commit
ba19537f4e
3 changed files with 66 additions and 18 deletions
|
@ -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])) {
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
|
||||
// Remove Tags.
|
||||
// Interpret escaped new lines and special chars.
|
||||
// Trim, e.g. trailing or leading new lines.
|
||||
return trim(stripcslashes(strip_tags(implode(' ', $content))));
|
||||
return [
|
||||
// Remove Tags.
|
||||
// Interpret escaped new lines and special chars.
|
||||
// Trim, e.g. trailing or leading new lines.
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,13 +136,15 @@ class QueryFactory
|
|||
];
|
||||
}
|
||||
|
||||
$query = ArrayUtility::arrayMergeRecursiveOverrule($query, [
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'should' => $boostQueryParts,
|
||||
if (!empty($boostQueryParts)) {
|
||||
$query = ArrayUtility::arrayMergeRecursiveOverrule($query, [
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'should' => $boostQueryParts,
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function addFactorBoost(array &$query)
|
||||
|
|
Loading…
Reference in a new issue