diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index eeef7c6..8c967e4 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -1,16 +1,15 @@ services: - # EventListener + Service automatisch laden MummertMedia\ContaoMeilisearchBundle\: resource: '../../{Command,Cron,EventListener,Service}' autowire: true autoconfigure: true - public: true - # IndexPageListener als Contao-Hook registrieren + # IndexPageListener als Contao-Hook MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener: tags: - { name: contao.hook, hook: indexPage, method: onIndexPage } + # täglicher Reindex MummertMedia\ContaoMeilisearchBundle\Cron\MeilisearchIndexCron: tags: - { name: contao.cron, interval: daily } \ No newline at end of file diff --git a/src/Service/MeilisearchImageHelper.php b/src/Service/MeilisearchImageHelper.php new file mode 100644 index 0000000..5940a70 --- /dev/null +++ b/src/Service/MeilisearchImageHelper.php @@ -0,0 +1,62 @@ +framework->initialize(); + + /** @var FilesModel|null $file */ + $file = FilesModel::findByUuid($uuid); + if (!$file) { + return null; + } + + // ImageSize aus tl_settings + $imageSizeId = (int) Config::get('meilisearch_imagesize'); + + // Fallback: Originaldatei + if ($imageSizeId <= 0) { + return $file->path; + } + + try { + $figure = $this->studio + ->createFigureBuilder() + ->from($file->path) + ->setSize($imageSizeId) + ->build(); + + $image = $figure->getImage(); + if ($image === null) { + return null; + } + + return $image->getUrl(); + } catch (\Throwable) { + // bewusst still – kein Bild = kein Index-Fail + return null; + } + } +} \ No newline at end of file diff --git a/src/Service/MeilisearchIndexService.php b/src/Service/MeilisearchIndexService.php index 97f8f0c..5dd0d16 100644 --- a/src/Service/MeilisearchIndexService.php +++ b/src/Service/MeilisearchIndexService.php @@ -15,6 +15,7 @@ class MeilisearchIndexService public function __construct( private readonly Connection $connection, private readonly ContaoFramework $framework, + private readonly MeilisearchImageHelper $imageHelper, ) {} /** @@ -67,7 +68,7 @@ class MeilisearchIndexService foreach ($rows as $row) { $type = $this->detectTypeFromMeta($row['meta'] ?? null); - $documents[] = [ + $doc = [ 'id' => $type . '_' . $row['id'], 'type' => $type, 'title' => $row['title'], @@ -78,6 +79,16 @@ class MeilisearchIndexService 'keywords' => (string) ($row['keywords'] ?? ''), 'priority' => (int) ($row['priority'] ?? 0), ]; + + // ✅ Bild aus UUID erzeugen (falls vorhanden) + if (!empty($row['imagepath'])) { + $imagePath = $this->imageHelper->resolveImagePath($row['imagepath']); + if ($imagePath !== null) { + $doc['poster'] = $imagePath; + } + } + + $documents[] = $doc; } $index->addDocuments($documents); @@ -104,7 +115,7 @@ class MeilisearchIndexService 'id' => $fileType . '_' . $row['id'], 'type' => $fileType, 'title' => $row['title'], - 'text' => $row['text'], // ✅ korrekt + 'text' => $row['text'], 'url' => $row['url'], 'checksum' => $row['checksum'], ]; @@ -112,6 +123,7 @@ class MeilisearchIndexService $index->addDocuments($documents); } + private function detectTypeFromMeta(?string $meta): string { if (!$meta) {