update Index Command

This commit is contained in:
Jürgen Mummert
2026-01-09 16:36:24 +01:00
parent f1c864dfca
commit 02b1657f19
+15 -29
View File
@@ -72,7 +72,7 @@ class MeilisearchIndexService
} }
$this->indexTlSearch($index); $this->indexTlSearch($index);
$this->indexTlSearchPdf($index); $this->indexTlSearchFiles($index);
} }
private function ensureIndexSettings(Indexes $index): void private function ensureIndexSettings(Indexes $index): void
@@ -80,6 +80,7 @@ class MeilisearchIndexService
$index->updateSettings([ $index->updateSettings([
'searchableAttributes' => ['title', 'keywords', 'text'], 'searchableAttributes' => ['title', 'keywords', 'text'],
'sortableAttributes' => ['priority', 'startDate'], 'sortableAttributes' => ['priority', 'startDate'],
'filterableAttributes' => ['type', 'filetype'],
]); ]);
} }
@@ -132,7 +133,7 @@ class MeilisearchIndexService
} }
/** /**
* tl_search indexieren * tl_search indexieren (Seiten / News / Events)
*/ */
private function indexTlSearch(Indexes $index): void private function indexTlSearch(Indexes $index): void
{ {
@@ -164,13 +165,11 @@ class MeilisearchIndexService
} }
} }
$cleanText = $this->stripMeilisearchMeta((string) $row['text']);
$doc = [ $doc = [
'id' => $type . '_' . $row['id'], 'id' => $type . '_' . $row['id'],
'type' => $type, 'type' => $type,
'title' => $row['title'], 'title' => $row['title'],
'text' => $cleanText, 'text' => $this->stripMeilisearchMeta((string) $row['text']),
'url' => $row['url'], 'url' => $row['url'],
'protected' => (bool) $row['protected'], 'protected' => (bool) $row['protected'],
'checksum' => $row['checksum'], 'checksum' => $row['checksum'],
@@ -192,31 +191,24 @@ class MeilisearchIndexService
$documents[] = $doc; $documents[] = $doc;
} catch (\Throwable $e) { } catch (\Throwable $e) {
error_log( error_log('[ContaoMeilisearch] Failed to build tl_search document: ' . $e->getMessage());
'[ContaoMeilisearch] Failed to build document for tl_search ID '
. ($row['id'] ?? '?') . ': ' . $e->getMessage()
);
} }
} }
if ($documents !== []) { if ($documents !== []) {
try {
$index->addDocuments($documents); $index->addDocuments($documents);
} catch (\Throwable $e) {
error_log('[ContaoMeilisearch] Failed to add tl_search documents: ' . $e->getMessage());
}
} }
} }
/** /**
* tl_search_pdf indexieren * tl_search_files indexieren (PDF / Office)
*/ */
private function indexTlSearchPdf(Indexes $index): void private function indexTlSearchFiles(Indexes $index): void
{ {
try { try {
$rows = $this->connection->fetchAllAssociative('SELECT * FROM tl_search_pdf'); $rows = $this->connection->fetchAllAssociative('SELECT * FROM tl_search_files');
} catch (\Throwable $e) { } catch (\Throwable $e) {
error_log('[ContaoMeilisearch] Failed to read tl_search_pdf: ' . $e->getMessage()); error_log('[ContaoMeilisearch] Failed to read tl_search_files: ' . $e->getMessage());
return; return;
} }
@@ -233,10 +225,11 @@ class MeilisearchIndexService
: 'pdf'; : 'pdf';
$documents[] = [ $documents[] = [
'id' => $fileType . '_' . $row['id'], 'id' => 'file_' . $row['id'],
'type' => $fileType, 'type' => 'file',
'title' => $row['title'], 'filetype' => $fileType,
'text' => $this->stripMeilisearchMeta((string) $row['text']), 'title' => $row['title'] ?: basename($row['url']),
'text' => (string) $row['text'],
'url' => $row['url'], 'url' => $row['url'],
'checksum' => $row['checksum'], 'checksum' => $row['checksum'],
'poster' => self::FILETYPE_ICON_MAP[$fileType] 'poster' => self::FILETYPE_ICON_MAP[$fileType]
@@ -244,19 +237,12 @@ class MeilisearchIndexService
]; ];
} catch (\Throwable $e) { } catch (\Throwable $e) {
error_log( error_log('[ContaoMeilisearch] Failed to build file document: ' . $e->getMessage());
'[ContaoMeilisearch] Failed to build PDF document for ID '
. ($row['id'] ?? '?') . ': ' . $e->getMessage()
);
} }
} }
if ($documents !== []) { if ($documents !== []) {
try {
$index->addDocuments($documents); $index->addDocuments($documents);
} catch (\Throwable $e) {
error_log('[ContaoMeilisearch] Failed to add tl_search_pdf documents: ' . $e->getMessage());
}
} }
} }