diff --git a/Classes/Domain/Model/Document.php b/Classes/Domain/Model/Document.php index 330aac6..9fea1b1 100644 --- a/Classes/Domain/Model/Document.php +++ b/Classes/Domain/Model/Document.php @@ -20,6 +20,7 @@ class Document extends AbstractDomainObject protected string $content = ''; protected string $type = ''; protected array $_formatted = []; + protected int $languageId = 0; public function getId(): string { @@ -91,6 +92,16 @@ public function setType(string $type): void $this->type = strtolower($type); } + public function getLanguageId(): int + { + return $this->languageId; + } + + public function setLanguageId(int $languageId): void + { + $this->languageId = $languageId; + } + public function setFormatted(array $_formatted): void { if ($_formatted['content']) { @@ -107,6 +118,12 @@ public static function createFromTSFE(TypoScriptFrontendController $tsfe): Docum preg_match('/(.*?)<\/body>/s', $tsfe->content, $content); } + // Remove code that shouldn't be indexed + $content = preg_replace('//s', '', $content); + $content = preg_replace('//s', '', $content); + $content = preg_replace('//s', '', $content); + $content = preg_replace('//s', '', $content); + // Remove query and fragments from URL $uri = $tsfe->cObj->getRequest()->getUri(); $url = $uri->getScheme() . '://' . $uri->getAuthority(); @@ -122,11 +139,12 @@ public static function createFromTSFE(TypoScriptFrontendController $tsfe): Docum $document = new Document(); $document->setId(md5($url)); $document->setRootPageId($tsfe->getSite()->getRootPageId() ?? 0); - $document->setContent($content[0] ?? ''); + $document->setContent(implode(PHP_EOL, $content ?? [])); $document->setType('page'); $document->setTitle($tsfe->page['title'] ?? ''); $document->setUrl($url); $document->setCrdate($tsfe->page['crdate']); + $document->setLanguageId($tsfe->getLanguage()->getLanguageId() ?? 0); return $document; } @@ -141,6 +159,7 @@ public function toArray(): array 'url' => $this->url, 'content' => $this->content, 'type' => $this->type, + 'languageId' => $this->languageId, ]; } } diff --git a/Classes/Service/IndexService.php b/Classes/Service/IndexService.php index 2337b5b..ae827e2 100644 --- a/Classes/Service/IndexService.php +++ b/Classes/Service/IndexService.php @@ -33,7 +33,7 @@ public function __construct() try { if ($this->client->isHealthy()) { $this->client->index($this->index)->updateSettings([ - 'filterableAttributes' => ['rootPageId', 'type'], + 'filterableAttributes' => ['rootPageId', 'type', 'languageId'], 'sortableAttributes' => ['crdate'], ]); } @@ -106,6 +106,7 @@ public function checkForFiles(TypoScriptFrontendController $tsfe) $document->setContent($content); $document->setType('pdf'); $document->setCrdate(filemtime($absolutePath)); + $document->setLanguageId(-1); $this->add($document); } diff --git a/Classes/Service/SearchService.php b/Classes/Service/SearchService.php index 3780e2e..53128e3 100644 --- a/Classes/Service/SearchService.php +++ b/Classes/Service/SearchService.php @@ -46,6 +46,7 @@ public function search(string $query, string $sorting = 'crdate_desc', array $ty // Filter by checking the rootPageId is in the rootline 'filter' => [ 'rootPageId = ' . $GLOBALS['TSFE']->getSite()->getRootPageId(), + 'languageId IN [-1,' . $GLOBALS['TSFE']->getLanguage()->getLanguageId() . ']', $typesFilter, ], ]);