Add Index Listener

This commit is contained in:
Jürgen Mummert
2025-12-22 21:12:36 +01:00
parent 013f844804
commit b465d5ed84
3 changed files with 34 additions and 31 deletions
@@ -9,32 +9,28 @@ class MeilisearchEventMarkerListener
{ {
public function onParseTemplate(Template $template): void public function onParseTemplate(Template $template): void
{ {
// ✅ Nur Event-Reader // DEBUG: Immer sichtbar, sobald parseTemplate überhaupt läuft
$GLOBALS['MEILISEARCH_MARKERS']['event']['debug_hook'] = 'parseTemplate_called:' . $template->getName();
if ($template->getName() !== 'mod_eventreader') { if ($template->getName() !== 'mod_eventreader') {
return; return;
} }
// ✅ Event kommt DIREKT aus dem Template // DEBUG: Was ist im Template vorhanden?
if ( $GLOBALS['MEILISEARCH_MARKERS']['event']['debug_has_event_prop'] = isset($template->event) ? 'yes' : 'no';
!isset($template->event) ||
!$template->event instanceof CalendarEventsModel if (!isset($template->event) || !$template->event instanceof CalendarEventsModel) {
) {
return; return;
} }
$event = $template->event; $event = $template->event;
$priority = (int) ($event->priority ?? 0); $GLOBALS['MEILISEARCH_MARKERS']['event'] = array_merge(
$keywords = trim((string) ($event->keywords ?? '')); $GLOBALS['MEILISEARCH_MARKERS']['event'] ?? [],
[
if ($priority <= 0 && $keywords === '') { 'priority' => (int) ($event->priority ?? 0),
return; 'keywords' => trim((string) ($event->keywords ?? '')),
} ]
);
// ✅ In globale Marker schreiben (merge-fähig)
$GLOBALS['MEILISEARCH_MARKERS']['event'] = [
'priority' => $priority > 0 ? $priority : null,
'keywords' => $keywords !== '' ? $keywords : null,
];
} }
} }
@@ -10,19 +10,21 @@ class MeilisearchPageMarkerListener
{ {
public function onOutputFrontendTemplate(string $buffer, string $template): string public function onOutputFrontendTemplate(string $buffer, string $template): string
{ {
// Nur im Frontend
if (!isset($GLOBALS['objPage']) || !$GLOBALS['objPage'] instanceof PageModel) { if (!isset($GLOBALS['objPage']) || !$GLOBALS['objPage'] instanceof PageModel) {
return $buffer; return $buffer;
} }
// ✅ Vorhandene Marker (event/news) übernehmen // 🔹 Marker aus vorherigen Listenern übernehmen
$markers = $GLOBALS['MEILISEARCH_MARKERS'] ?? []; $markers = $GLOBALS['MEILISEARCH_MARKERS'] ?? [];
$page = $GLOBALS['objPage']; $page = $GLOBALS['objPage'];
$priority = (int) ($page->priority ?? 0); // --- Page-Daten ---
$keywords = trim((string) ($page->keywords ?? '')); $pagePriority = (int) ($page->priority ?? 0);
$pageKeywords = trim((string) ($page->keywords ?? ''));
// searchimage: Page → Fallback // --- Page searchimage → Fallback ---
$searchImageUuid = null; $searchImageUuid = null;
if (!empty($page->searchimage)) { if (!empty($page->searchimage)) {
@@ -32,19 +34,21 @@ class MeilisearchPageMarkerListener
if (!$searchImageUuid) { if (!$searchImageUuid) {
$fallback = Config::get('meilisearch_fallback_image'); $fallback = Config::get('meilisearch_fallback_image');
if ($fallback) { if ($fallback) {
// tl_settings speichert varbinary(16) → UUID
$searchImageUuid = StringUtil::binToUuid($fallback); $searchImageUuid = StringUtil::binToUuid($fallback);
} }
} }
// Page-Marker NUR ergänzen, nicht alles überschreiben // Page-Marker nur ergänzen (niemals löschen)
$markers['page'] = [ $markers['page'] = array_merge(
'priority' => $priority > 0 ? $priority : null, $markers['page'] ?? [],
'keywords' => $keywords !== '' ? $keywords : null, [
'priority' => $pagePriority > 0 ? $pagePriority : null,
'keywords' => $pageKeywords !== '' ? $pageKeywords : null,
'searchimage' => $searchImageUuid ?: null, 'searchimage' => $searchImageUuid ?: null,
]; ]
);
// Ausgabe bauen // 🔹 Ausgabe bauen
$lines = ['MEILISEARCH']; $lines = ['MEILISEARCH'];
foreach ($markers as $scope => $data) { foreach ($markers as $scope => $data) {
@@ -61,6 +65,7 @@ class MeilisearchPageMarkerListener
} }
} }
// Wenn nichts drinsteht → nichts anhängen
if (count($lines) === 1) { if (count($lines) === 1) {
return $buffer; return $buffer;
} }
+3 -1
View File
@@ -25,4 +25,6 @@ $GLOBALS['TL_HOOKS']['parseTemplate'][] = [
'onParseTemplate', 'onParseTemplate',
]; ];
$GLOBALS['MEILISEARCH_MARKERS'] = []; if (!isset($GLOBALS['MEILISEARCH_MARKERS'])) {
$GLOBALS['MEILISEARCH_MARKERS'] = [];
}