Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multi-language support #12

Merged
merged 5 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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($tsfe->getLanguage()->getLanguageId() ?? 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