Skip to content

Commit

Permalink
feat: add multi-language support
Browse files Browse the repository at this point in the history
  • Loading branch information
runepiper committed Mar 6, 2024
1 parent 6a0c622 commit b4e8f35
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Classes/Domain/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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']) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -141,6 +153,7 @@ public function toArray(): array
'url' => $this->url,
'content' => $this->content,
'type' => $this->type,
'languageId' => $this->languageId,
];
}
}
3 changes: 2 additions & 1 deletion Classes/Service/IndexService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
]);
}
Expand Down Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions Classes/Service/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
]);
Expand Down

0 comments on commit b4e8f35

Please sign in to comment.