diff --git a/src/Resources/contao/templates/frontend_module/mod_meilisearch_search.html.twig b/src/Resources/contao/templates/frontend_module/mod_meilisearch_search.html.twig index d75599f..7986514 100644 --- a/src/Resources/contao/templates/frontend_module/mod_meilisearch_search.html.twig +++ b/src/Resources/contao/templates/frontend_module/mod_meilisearch_search.html.twig @@ -90,7 +90,7 @@ Contao 5 – Frontend Module Template cropLength: 50, cropMarker: '…', - sort: ['priority:desc'] + sort: ['startDate:asc', 'priority:desc'] }); renderResults(response.hits); diff --git a/src/Service/MeilisearchIndexService.php b/src/Service/MeilisearchIndexService.php index ee563f4..5340e64 100644 --- a/src/Service/MeilisearchIndexService.php +++ b/src/Service/MeilisearchIndexService.php @@ -83,6 +83,7 @@ class MeilisearchIndexService ], 'sortableAttributes' => [ 'priority', + 'startDate', ], ]); } @@ -94,11 +95,25 @@ class MeilisearchIndexService return; } + $indexPastEvents = (bool) Config::get('meilisearch_index_past_events'); + $today = strtotime('today'); + $documents = []; foreach ($rows as $row) { $type = $this->detectTypeFromMeta($row['meta'] ?? null); + // 🛑 VERGANGENE EVENTS FILTERN + if ($type === 'event' && !$indexPastEvents) { + if (!empty($row['startDate'])) { + $eventStart = (int) $row['startDate']; + + if ($eventStart < $today) { + continue; // ⛔ Event überspringen + } + } + } + $doc = [ 'id' => $type . '_' . $row['id'], 'type' => $type, @@ -111,7 +126,12 @@ class MeilisearchIndexService 'priority' => (int) ($row['priority'] ?? 0), ]; - // ✅ Bild aus UUID erzeugen (falls vorhanden) + // 📅 startDate nur für Events übernehmen + if ($type === 'event' && !empty($row['startDate'])) { + $doc['startDate'] = (int) $row['startDate']; + } + + // 🖼️ Bild aus UUID erzeugen if (!empty($row['imagepath'])) { $imagePath = $this->imageHelper->resolveImagePath($row['imagepath']); if ($imagePath !== null) { @@ -122,7 +142,9 @@ class MeilisearchIndexService $documents[] = $doc; } - $index->addDocuments($documents); + if ($documents !== []) { + $index->addDocuments($documents); + } } private function indexTlSearchPdf(Indexes $index): void