From b4e8f35444d5f9f2b79c55804061d279980dd2ee Mon Sep 17 00:00:00 2001 From: Rune Piper Date: Wed, 6 Mar 2024 10:07:04 +0100 Subject: [PATCH] feat: add multi-language support --- Classes/Domain/Model/Document.php | 13 +++++++++++++ Classes/Service/IndexService.php | 3 ++- Classes/Service/SearchService.php | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Classes/Domain/Model/Document.php b/Classes/Domain/Model/Document.php index 330aac6..6f3b4af 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']) { @@ -127,6 +138,7 @@ public static function createFromTSFE(TypoScriptFrontendController $tsfe): Docum $document->setTitle($tsfe->page['title'] ?? ''); $document->setUrl($url); $document->setCrdate($tsfe->page['crdate']); + $document->setLanguageId(0); return $document; } @@ -141,6 +153,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..427ac0f 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, ], ]);