Compare commits
275 Commits
b59bda40fc
..
0.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 56d806c579 | |||
| 2989d205d7 | |||
| 02b1657f19 | |||
| f1c864dfca | |||
| 5cd8286286 | |||
| 0fa0642618 | |||
| 874ed0e656 | |||
| b91281614b | |||
| 4c1b4ac4b7 | |||
| 1f75418d9b | |||
| 278ae9f36f | |||
| 17ecdaec17 | |||
| 8b22467799 | |||
| cd9b918aff | |||
| 8d4af1f61d | |||
| f16e7a98d1 | |||
| c223ae692f | |||
| b4cd9199c8 | |||
| 6329c9e790 | |||
| d2c9263755 | |||
| e9f06f7cc9 | |||
| 6d2f4458bc | |||
| 9adad9ca8d | |||
| 356b18c8c8 | |||
| 7dc30c435f | |||
| ac001fb53c | |||
| 6ea558bbca | |||
| cf0a84b85e | |||
| d9b8646835 | |||
| b684267541 | |||
| 0e20a813af | |||
| c2a01d66f8 | |||
| 71f8d2cc95 | |||
| 41c9db954d | |||
| 7613d20831 | |||
| 46e5665c36 | |||
| 322628de6c | |||
| b39d24b832 | |||
| 6287ff54de | |||
| e245483b2a | |||
| 5c30eed719 | |||
| 1f6e115ae6 | |||
| ae28c619da | |||
| c2bef6dad5 | |||
| c5ab9f28c8 | |||
| e609dca6c8 | |||
| 9b10b5cc13 | |||
| cf5986e02b | |||
| 44db711c52 | |||
| 13d1e0105c | |||
| 90bd2c77f2 | |||
| 2a2c68cfb1 | |||
| 987441700f | |||
| 04f3e76c8f | |||
| 2a22253f18 | |||
| 0fd119f873 | |||
| 9edb1e4713 | |||
| e4c8473999 | |||
| 5102f98e2b | |||
| 0507d7d992 | |||
| 31def907f6 | |||
| 0cf9703a9b | |||
| b0337dcc6c | |||
| 37b50f9140 | |||
| 1192ff4bf4 | |||
| da9edd59ba | |||
| 186471b68c | |||
| e6cb8a6f41 | |||
| 75f8df5817 | |||
| e5cce34619 | |||
| c645e3caa8 | |||
| 2832da4736 | |||
| 4cf0d7315b | |||
| ff54ed5aa4 | |||
| 97c25c5abd | |||
| 1948227a06 | |||
| 89f12df84a | |||
| 59ff2c3ed0 | |||
| 8d505b70ee | |||
| fe2fd91697 | |||
| 952f2472c4 | |||
| c0c83f2e66 | |||
| be9b679922 | |||
| 76e081e51e | |||
| 131e24fe2e | |||
| cfffdf2323 | |||
| 0366995021 | |||
| dc141b7abb | |||
| 3041ff59b5 | |||
| e61293d5ba | |||
| 60aa99199b | |||
| e8e80ff48b | |||
| 3a94062a7a | |||
| 70321dc497 | |||
| b6a86156d9 | |||
| 03bcc04537 | |||
| 3321049302 | |||
| 459f007f8d | |||
| 2c31526be7 | |||
| 263d6d42ac | |||
| 0ed5f4a51d | |||
| 2c53b7862e | |||
| 973f3f5b3e | |||
| 5be9af1f20 | |||
| bd345252fe | |||
| 5cf81a6a52 | |||
| da379116d1 | |||
| e7e8917d92 | |||
| 542a8fc1a3 | |||
| 6c3bd63073 | |||
| 7e5518888d | |||
| 4ecbc0ab1a | |||
| 5f900ca5eb | |||
| e38ebf8a02 | |||
| a4e18a84fd | |||
| b57828d4e2 | |||
| 1cf780a585 | |||
| fb92fe01e9 | |||
| e11684d4be | |||
| f807f44e12 | |||
| 4cd1913079 | |||
| 640cccc928 | |||
| fa97460877 | |||
| 340e6c7de0 | |||
| d3e1149cec | |||
| e865dc48bd | |||
| b184b5f3c4 | |||
| 2cef524ccf | |||
| d115e63c08 | |||
| 7d31390cdd | |||
| 7b851001f0 | |||
| 66c119ad66 | |||
| c40efd2061 | |||
| 654a1a8ec8 | |||
| 8f3a0ad1b2 | |||
| 7415df53d7 | |||
| 8c82f948b4 | |||
| b334dc46a7 | |||
| 9dd7dbd2b2 | |||
| a83b101ed7 | |||
| 516233c434 | |||
| 854713a461 | |||
| d7b9174f32 | |||
| 5b1d68eb06 | |||
| bbb4d5cc6c | |||
| 6e6f5904d9 | |||
| 85cbf2a235 | |||
| 6d86faa62f | |||
| 798aaadb7e | |||
| 8f3b525563 | |||
| 497b46f113 | |||
| 08c1f8a015 | |||
| b610a1e128 | |||
| c8069b1ce3 | |||
| e3c29d70e9 | |||
| 9831c0c72d | |||
| 693306c03c | |||
| f156f57e2b | |||
| 15d14198fe | |||
| 1ae7f910ca | |||
| ebbfdface7 | |||
| af9d74e746 | |||
| 8caf5afa97 | |||
| 7025d3c013 | |||
| 48d5316085 | |||
| 020e3500da | |||
| 2bf1df13b4 | |||
| 9fa59c4b1a | |||
| 4a09f8530a | |||
| 0cee7b1e7f | |||
| 44b5c9717a | |||
| afdfa5c807 | |||
| e2c7748342 | |||
| cb63b1391e | |||
| b844bc4e3f | |||
| 51dadaa0b6 | |||
| acfb81b132 | |||
| 5a65aa00eb | |||
| c71554b18c | |||
| 9aa3597c2e | |||
| 21708dac75 | |||
| 872a242794 | |||
| 22c6a3e0b6 | |||
| 22c73baa5c | |||
| 093ac084bb | |||
| d77af88480 | |||
| 8507631cd2 | |||
| dbf58d0163 | |||
| b98cc225fc | |||
| f781727aaf | |||
| 2182ac2409 | |||
| 64ebc8e4a5 | |||
| c90d8ed859 | |||
| ca6878c50a | |||
| 8a90d2622d | |||
| d44b84094d | |||
| 33f7b01c69 | |||
| c8ffb6d696 | |||
| c72f5faf32 | |||
| 1c433f3737 | |||
| 405a71a7f6 | |||
| 19add69376 | |||
| fb8cb4f452 | |||
| 1833c2044e | |||
| 50a201a490 | |||
| 86bb2d8e8d | |||
| faaa6fdcac | |||
| 1fd612e530 | |||
| 4488e31a2b | |||
| b6758fc3c2 | |||
| 4555315496 | |||
| d9e0c2ef51 | |||
| 1b0a4f1975 | |||
| 7f70e32995 | |||
| 93ad88e77d | |||
| 477815e964 | |||
| 8108148f24 | |||
| e325ec7a36 | |||
| ab2dc091f7 | |||
| d9706846de | |||
| 01949362ce | |||
| ac1db3ff9a | |||
| f41357bee5 | |||
| 3948d20261 | |||
| b465d5ed84 | |||
| 013f844804 | |||
| 985573ef63 | |||
| f14c1e34ff | |||
| ef9d2e0bac | |||
| e1ba9645b9 | |||
| dc0823b4ef | |||
| cb69f655ce | |||
| e795e5866c | |||
| c7af2566df | |||
| 7c5b171d42 | |||
| c4b1d653d0 | |||
| 6d22552a14 | |||
| 484e3faf16 | |||
| d846d73b26 | |||
| 5de05412ba | |||
| 66014e6bb7 | |||
| a3a65002bb | |||
| d869f1000d | |||
| 3d491b5a0f | |||
| 99d974af17 | |||
| 8a704e965f | |||
| 06dc2a8194 | |||
| d5122e7e9a | |||
| 0ada038d21 | |||
| b6e6aacf83 | |||
| da1bbfa443 | |||
| 03467246a4 | |||
| 1ba82dfb50 | |||
| db2ceb3aeb | |||
| f40c194e13 | |||
| 94c2fa74d6 | |||
| f702e8e07a | |||
| ddf5f7172c | |||
| 6a4c699ae0 | |||
| 99587499d3 | |||
| 2019c59cf8 | |||
| f94a688177 | |||
| 0d6b4a2a9a | |||
| 18145098cb | |||
| 40c7ae9a54 | |||
| 4793b25814 | |||
| 05e87fd592 | |||
| a06a938818 | |||
| 3f703cf5db | |||
| d4ca5ae6de | |||
| 37e77f6bb1 | |||
| 76a56af9f6 | |||
| 796e48c83c | |||
| 2727be2b05 | |||
| aff120670e |
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "mummert/contao-meilisearch-bundle",
|
||||
"name": "mummert-media/contao-meilisearch-bundle",
|
||||
"description": "Contao Meilisearch integration bundle",
|
||||
"type": "contao-bundle",
|
||||
"license": "MIT",
|
||||
@@ -12,10 +12,10 @@
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mummert\\ContaoMeilisearchBundle\\": "src/"
|
||||
"MummertMedia\\ContaoMeilisearchBundle\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"contao-manager-plugin": "Mummert\\ContaoMeilisearchBundle\\ContaoManager\\Plugin"
|
||||
"contao-manager-plugin": "MummertMedia\\ContaoMeilisearchBundle\\ContaoManager\\Plugin"
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Command;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\Command;
|
||||
|
||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Command;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\Command;
|
||||
|
||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||
use Contao\Database;
|
||||
use Contao\System;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
@@ -23,18 +22,18 @@ class MeilisearchFilesParseCommand extends Command
|
||||
{
|
||||
$this
|
||||
->setName('meilisearch:files:parse')
|
||||
->setDescription('Parse indexed files via Apache Tika and enrich tl_search_files')
|
||||
->setDescription('Parse indexed files via Apache Tika and store extracted text')
|
||||
->addOption(
|
||||
'limit',
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
'Maximum number of files to check per run'
|
||||
'Maximum number of files to check per run (optional)'
|
||||
)
|
||||
->addOption(
|
||||
'dry-run',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Do not send files to Tika'
|
||||
'Do not send files to Tika, just show what would be parsed'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -45,9 +44,11 @@ class MeilisearchFilesParseCommand extends Command
|
||||
|
||||
$dryRun = (bool) $input->getOption('dry-run');
|
||||
|
||||
// ---- LIMIT: nur wenn explizit gesetzt
|
||||
$limitOption = $input->getOption('limit');
|
||||
$limit = $limitOption !== null ? max(1, (int) $limitOption) : null;
|
||||
|
||||
// ---- Tika URL
|
||||
$tikaUrl = rtrim((string) ($GLOBALS['TL_CONFIG']['meilisearch_tika_url'] ?? ''), '/');
|
||||
if ($tikaUrl === '') {
|
||||
$output->writeln('<error>Tika URL not configured</error>');
|
||||
@@ -56,6 +57,7 @@ class MeilisearchFilesParseCommand extends Command
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
// ---- Files laden
|
||||
$sql = "SELECT * FROM tl_search_files ORDER BY tstamp ASC";
|
||||
if ($limit !== null) {
|
||||
$sql .= " LIMIT " . (int) $limit;
|
||||
@@ -74,12 +76,11 @@ class MeilisearchFilesParseCommand extends Command
|
||||
|
||||
foreach ($files as $file) {
|
||||
|
||||
$originalUrl = (string) $file['url'];
|
||||
$existingTitle = trim((string) ($file['title'] ?? ''));
|
||||
$normalized = $originalUrl;
|
||||
$originalUrl = (string) $file['url'];
|
||||
$normalized = $originalUrl;
|
||||
|
||||
// -------------------------------------------------
|
||||
// Normalize URL
|
||||
// 1) ?file=files/…
|
||||
// -------------------------------------------------
|
||||
if (str_contains($normalized, '?')) {
|
||||
$parts = parse_url($normalized);
|
||||
@@ -94,20 +95,26 @@ class MeilisearchFilesParseCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// 2) Fragment entfernen
|
||||
// -------------------------------------------------
|
||||
$normalized = strtok($normalized, '#');
|
||||
$normalized = rawurldecode($normalized);
|
||||
$normalized = ltrim($normalized, '/');
|
||||
|
||||
// -------------------------------------------------
|
||||
// 3) URL-Decoding
|
||||
// -------------------------------------------------
|
||||
$normalized = rawurldecode($normalized);
|
||||
|
||||
// -------------------------------------------------
|
||||
// 4) Nur lokale files/
|
||||
// -------------------------------------------------
|
||||
$normalized = ltrim($normalized, '/');
|
||||
if (!str_starts_with($normalized, 'files/')) {
|
||||
$this->log('Not in files/, skip', ['url' => $originalUrl]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$root = defined('TL_ROOT')
|
||||
? TL_ROOT
|
||||
: System::getContainer()->getParameter('kernel.project_dir') . '/public';
|
||||
|
||||
$absolutePath = $root . '/' . $normalized;
|
||||
$absolutePath = TL_ROOT . '/' . $normalized;
|
||||
|
||||
if (!is_file($absolutePath)) {
|
||||
$this->log('File missing, skip', [
|
||||
@@ -121,7 +128,7 @@ class MeilisearchFilesParseCommand extends Command
|
||||
$checksum = md5($normalized . '|' . $mtime);
|
||||
|
||||
// -------------------------------------------------
|
||||
// Skip unchanged
|
||||
// 5) Skip unchanged
|
||||
// -------------------------------------------------
|
||||
if ($file['checksum'] === $checksum && !empty($file['text'])) {
|
||||
continue;
|
||||
@@ -133,7 +140,7 @@ class MeilisearchFilesParseCommand extends Command
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// MIME-Type
|
||||
// 6) MIME-Type
|
||||
// -------------------------------------------------
|
||||
$ext = strtolower(pathinfo($normalized, PATHINFO_EXTENSION));
|
||||
|
||||
@@ -151,12 +158,12 @@ class MeilisearchFilesParseCommand extends Command
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// Tika BODY (roher Plaintext)
|
||||
// 7) Tika parse
|
||||
// -------------------------------------------------
|
||||
try {
|
||||
$this->log('Parsing file', ['url' => $normalized]);
|
||||
|
||||
$bodyResponse = $client->request(
|
||||
$response = $client->request(
|
||||
'PUT',
|
||||
$tikaUrl . '/tika/main',
|
||||
[
|
||||
@@ -168,98 +175,31 @@ class MeilisearchFilesParseCommand extends Command
|
||||
]
|
||||
);
|
||||
|
||||
$text = trim((string) $bodyResponse->getContent(false));
|
||||
$text = trim((string) $response->getContent(false));
|
||||
|
||||
$db->prepare(
|
||||
"UPDATE tl_search_files
|
||||
SET text = ?, checksum = ?, file_mtime = ?, tstamp = ?
|
||||
WHERE id = ?"
|
||||
)->execute(
|
||||
$text,
|
||||
$checksum,
|
||||
$mtime,
|
||||
time(),
|
||||
$file['id']
|
||||
);
|
||||
|
||||
$this->log('File parsed', [
|
||||
'url' => $normalized,
|
||||
'chars' => mb_strlen($text),
|
||||
]);
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
$this->log('Body parse failed', [
|
||||
$this->log('Parse failed', [
|
||||
'url' => $normalized,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
continue;
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// TITLE: keep existing editor-defined title
|
||||
// -------------------------------------------------
|
||||
$title = $existingTitle !== '' ? $existingTitle : null;
|
||||
|
||||
// -------------------------------------------------
|
||||
// Tika METADATA (Title) – only if no existing title
|
||||
// -------------------------------------------------
|
||||
if ($title === null) {
|
||||
try {
|
||||
$metaResponse = $client->request(
|
||||
'PUT',
|
||||
$tikaUrl . '/meta',
|
||||
[
|
||||
'headers' => [
|
||||
'Accept' => 'application/json',
|
||||
'Content-Type' => $mimeType,
|
||||
],
|
||||
'body' => fopen($absolutePath, 'rb'),
|
||||
]
|
||||
);
|
||||
|
||||
$meta = json_decode($metaResponse->getContent(false), true);
|
||||
|
||||
$rawTitle =
|
||||
$meta['dc:title'][0]
|
||||
?? $meta['pdf:docinfo:title'][0]
|
||||
?? null;
|
||||
|
||||
if ($rawTitle) {
|
||||
$title = html_entity_decode(
|
||||
$rawTitle,
|
||||
ENT_QUOTES | ENT_HTML5,
|
||||
'UTF-8'
|
||||
);
|
||||
}
|
||||
|
||||
} catch (\Throwable) {
|
||||
// Metadata optional
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// TITLE → ASCII SAFE (only if newly generated)
|
||||
// -------------------------------------------------
|
||||
if ($existingTitle === '' && $title) {
|
||||
$title = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $title);
|
||||
$title = preg_replace('/\s+/', ' ', $title);
|
||||
$title = trim($title);
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// FALLBACK: Dateiname (only if still empty)
|
||||
// -------------------------------------------------
|
||||
if (!$title || strlen($title) < 5) {
|
||||
$title = pathinfo($normalized, PATHINFO_FILENAME);
|
||||
$title = str_replace(['_', '-'], ' ', $title);
|
||||
$title = preg_replace('/\s+/', ' ', $title);
|
||||
$title = trim($title);
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// Store result
|
||||
// -------------------------------------------------
|
||||
$db->prepare(
|
||||
"UPDATE tl_search_files
|
||||
SET text = ?, title = ?, checksum = ?, file_mtime = ?, tstamp = ?
|
||||
WHERE id = ?"
|
||||
)->execute(
|
||||
$text,
|
||||
$title,
|
||||
$checksum,
|
||||
$mtime,
|
||||
time(),
|
||||
$file['id']
|
||||
);
|
||||
|
||||
$this->log('File parsed', [
|
||||
'url' => $normalized,
|
||||
'chars' => mb_strlen($text),
|
||||
'title' => $title,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->log('Parser finished');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Command;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\Command;
|
||||
|
||||
use Mummert\ContaoMeilisearchBundle\Service\MeilisearchIndexService;
|
||||
use MummertMedia\ContaoMeilisearchBundle\Service\MeilisearchIndexService;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\ContaoManager;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\ContaoManager;
|
||||
|
||||
use Contao\CalendarBundle\ContaoCalendarBundle;
|
||||
use Contao\CoreBundle\ContaoCoreBundle;
|
||||
@@ -8,7 +8,7 @@ use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
|
||||
use Contao\ManagerPlugin\Bundle\Config\BundleConfig;
|
||||
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
|
||||
use Contao\NewsBundle\ContaoNewsBundle;
|
||||
use Mummert\ContaoMeilisearchBundle\ContaoMeilisearchBundle;
|
||||
use MummertMedia\ContaoMeilisearchBundle\ContaoMeilisearchBundle;
|
||||
|
||||
class Plugin implements BundlePluginInterface
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Controller\FrontendModule;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\Controller\FrontendModule;
|
||||
|
||||
use Contao\Config;
|
||||
use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\DependencyInjection;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\EventListener;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
||||
|
||||
use Contao\Config;
|
||||
use Contao\System;
|
||||
use Mummert\ContaoMeilisearchBundle\Service\MeilisearchFileHelper;
|
||||
|
||||
class IndexPageListener
|
||||
{
|
||||
public function __construct(
|
||||
private readonly MeilisearchFileHelper $fileHelper,
|
||||
) {
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
private function debug(string $message, array $context = []): void
|
||||
{
|
||||
// Debug bewusst immer aktiv (bis du es wieder entfernst)
|
||||
// Kontext kurz halten, damit Logs nicht explodieren
|
||||
$ctx = $context ? ' | ' . json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : '';
|
||||
error_log('[ContaoMeilisearch][IndexPageListener] ' . $message . $ctx);
|
||||
}
|
||||
@@ -76,6 +76,8 @@ class IndexPageListener
|
||||
$parsed['page']['keywords'] ?? null,
|
||||
];
|
||||
|
||||
$this->debug('Meta: keyword sources', ['sources' => $keywordSources]);
|
||||
|
||||
$keywords = [];
|
||||
foreach ($keywordSources as $src) {
|
||||
if (!is_string($src) || trim($src) === '') {
|
||||
@@ -90,41 +92,77 @@ class IndexPageListener
|
||||
$set['keywords'] = implode(' ', array_unique($keywords));
|
||||
}
|
||||
|
||||
// IMAGEPATH
|
||||
if (!empty($parsed['page']['searchimage'] ?? null)) {
|
||||
$set['imagepath'] = trim((string) $parsed['page']['searchimage']);
|
||||
$this->debug('Meta: keywords result', [
|
||||
'keywords' => $set['keywords'] ?? null,
|
||||
]);
|
||||
|
||||
// IMAGEPATH (UUID)
|
||||
$searchImage = $parsed['page']['searchimage'] ?? null;
|
||||
$this->debug('Meta: searchimage candidate', ['searchimage' => $searchImage]);
|
||||
|
||||
if (!empty($searchImage)) {
|
||||
$set['imagepath'] = trim((string) $searchImage);
|
||||
}
|
||||
|
||||
// STARTDATE
|
||||
if (is_numeric($parsed['event']['startDate'] ?? null)) {
|
||||
$set['startDate'] = (int) $parsed['event']['startDate'];
|
||||
$startDate =
|
||||
$parsed['event']['startDate']
|
||||
?? $parsed['news']['startDate']
|
||||
?? null;
|
||||
|
||||
$this->debug('Meta: startDate candidate', ['startDate' => $startDate]);
|
||||
|
||||
if (is_numeric($startDate) && (int) $startDate > 0) {
|
||||
$set['startDate'] = (int) $startDate;
|
||||
}
|
||||
|
||||
// CHECKSUM
|
||||
$checksumSeed = (string) ($data['checksum'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['keywords'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['priority'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['imagepath'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['startDate'] ?? '');
|
||||
try {
|
||||
$checksumSeed = (string) ($data['checksum'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['keywords'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['priority'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['imagepath'] ?? '');
|
||||
$checksumSeed .= '|' . ($set['startDate'] ?? '');
|
||||
|
||||
$set['checksum'] = md5($checksumSeed);
|
||||
$set['checksum'] = md5($checksumSeed);
|
||||
|
||||
$this->debug('Checksum generated', [
|
||||
'seed_preview' => substr($checksumSeed, 0, 120) . (strlen($checksumSeed) > 120 ? '…' : ''),
|
||||
'checksum' => $set['checksum'],
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
$this->debug('Failed to generate checksum', [
|
||||
'error' => $e->getMessage(),
|
||||
'class' => $e::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* =====================
|
||||
* DATEI-ERKENNUNG (NUR ERKENNUNG!)
|
||||
* DATEI-ERKENNUNG + UPSERT
|
||||
* =====================
|
||||
*/
|
||||
if ((int) ($data['protected'] ?? 0) !== 0) {
|
||||
$this->debug('Abort: protected page', ['protected' => $data['protected'] ?? null]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Config::get('meilisearch_index_files')) {
|
||||
$indexFiles = (bool) Config::get('meilisearch_index_files');
|
||||
|
||||
$this->debug('File indexing setting', [
|
||||
'meilisearch_index_files' => $indexFiles,
|
||||
]);
|
||||
|
||||
if (!$indexFiles) {
|
||||
$this->debug('Abort: file indexing disabled');
|
||||
return;
|
||||
}
|
||||
|
||||
$links = $this->findAllLinks($content);
|
||||
$this->debug('Links found', ['count' => count($links)]);
|
||||
|
||||
$fileLinks = [];
|
||||
|
||||
foreach ($links as $link) {
|
||||
@@ -136,15 +174,64 @@ class IndexPageListener
|
||||
|
||||
$this->debug('Indexable file links found', [
|
||||
'count' => count($fileLinks),
|
||||
'types' => array_count_values(array_column($fileLinks, 'type')),
|
||||
]);
|
||||
|
||||
if ($fileLinks) {
|
||||
$db = System::getContainer()->get('database_connection');
|
||||
$time = time();
|
||||
|
||||
foreach ($fileLinks as $file) {
|
||||
$this->fileHelper->collect(
|
||||
$file['url'],
|
||||
$file['type'],
|
||||
(int) ($data['pid'] ?? 0)
|
||||
$url = strtok($file['url'], '#');
|
||||
|
||||
$path = parse_url($url, PHP_URL_PATH);
|
||||
$abs = $path ? TL_ROOT . '/' . ltrim($path, '/') : null;
|
||||
|
||||
$mtime = ($abs && is_file($abs)) ? filemtime($abs) : 0;
|
||||
$checksum = md5($url . '|' . $mtime);
|
||||
|
||||
$existing = $db->fetchAssociative(
|
||||
'SELECT id, checksum FROM tl_search_files WHERE url = ?',
|
||||
[$url]
|
||||
);
|
||||
|
||||
if ($existing) {
|
||||
$db->update(
|
||||
'tl_search_files',
|
||||
[
|
||||
'tstamp' => $time,
|
||||
'last_seen' => $time,
|
||||
'page_id' => (int) ($data['pid'] ?? 0),
|
||||
'file_mtime' => $mtime,
|
||||
'checksum' => $checksum,
|
||||
],
|
||||
['id' => $existing['id']]
|
||||
);
|
||||
|
||||
$this->debug('File updated', [
|
||||
'url' => $url,
|
||||
'checksum' => $checksum,
|
||||
]);
|
||||
} else {
|
||||
$db->insert(
|
||||
'tl_search_files',
|
||||
[
|
||||
'tstamp' => $time,
|
||||
'last_seen' => $time,
|
||||
'type' => $file['type'],
|
||||
'url' => $url,
|
||||
'title' => $file['linkText'] ?? basename($url),
|
||||
'page_id' => (int) ($data['pid'] ?? 0),
|
||||
'file_mtime' => $mtime,
|
||||
'checksum' => $checksum,
|
||||
]
|
||||
);
|
||||
|
||||
$this->debug('File inserted', [
|
||||
'url' => $url,
|
||||
'checksum' => $checksum,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +281,11 @@ class IndexPageListener
|
||||
private function detectIndexableFileType(string $url): ?string
|
||||
{
|
||||
$url = strtok($url, '#');
|
||||
|
||||
$parts = parse_url($url);
|
||||
if (!$parts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!empty($parts['path'])) {
|
||||
$ext = strtolower(pathinfo($parts['path'], PATHINFO_EXTENSION));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\EventListener;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
||||
|
||||
use Contao\CalendarEventsModel;
|
||||
use Contao\Config;
|
||||
|
||||
@@ -2,24 +2,24 @@ services:
|
||||
# Alias MUSS vorhanden sein (richtig platziert)
|
||||
Psr\Container\ContainerInterface: '@service_container'
|
||||
|
||||
Mummert\ContaoMeilisearchBundle\:
|
||||
MummertMedia\ContaoMeilisearchBundle\:
|
||||
resource: '../../{Command,EventListener,Service}'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Mummert\ContaoMeilisearchBundle\EventListener\MeilisearchPageMarkerListener:
|
||||
MummertMedia\ContaoMeilisearchBundle\EventListener\MeilisearchPageMarkerListener:
|
||||
autowire: true
|
||||
autoconfigure: false
|
||||
tags:
|
||||
- { name: contao.hook, hook: outputFrontendTemplate, method: onOutputFrontendTemplate }
|
||||
|
||||
Mummert\ContaoMeilisearchBundle\EventListener\IndexPageListener:
|
||||
MummertMedia\ContaoMeilisearchBundle\EventListener\IndexPageListener:
|
||||
autowire: true
|
||||
autoconfigure: false
|
||||
tags:
|
||||
- { name: contao.hook, hook: indexPage, method: onIndexPage }
|
||||
|
||||
Mummert\ContaoMeilisearchBundle\Controller\FrontendModule\MeilisearchSearchController:
|
||||
MummertMedia\ContaoMeilisearchBundle\Controller\FrontendModule\MeilisearchSearchController:
|
||||
autowire: true
|
||||
autoconfigure: false
|
||||
tags:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Mummert\ContaoMeilisearchBundle\EventListener\MeilisearchPageMarkerListener;
|
||||
use MummertMedia\ContaoMeilisearchBundle\EventListener\MeilisearchPageMarkerListener;
|
||||
|
||||
|
||||
$GLOBALS['TL_HOOKS']['outputFrontendTemplate'][] = [
|
||||
|
||||
@@ -12,8 +12,7 @@ $GLOBALS['TL_DCA']['tl_search_files'] = [
|
||||
'url' => 'unique',
|
||||
'type' => 'index',
|
||||
'checksum' => 'index',
|
||||
'uuid' => 'index',
|
||||
'last_seen' => 'index',
|
||||
'last_seen' => 'index', // ⬅️ NEU (für Cleanup-Performance)
|
||||
],
|
||||
],
|
||||
],
|
||||
@@ -64,10 +63,6 @@ $GLOBALS['TL_DCA']['tl_search_files'] = [
|
||||
'sql' => "mediumtext NULL",
|
||||
],
|
||||
|
||||
'uuid' => [
|
||||
'sql' => "binary(16) NULL",
|
||||
],
|
||||
|
||||
/*
|
||||
* md5(url + filemtime)
|
||||
* → erkennt Änderungen zuverlässig
|
||||
|
||||
@@ -4,7 +4,6 @@ Contao 5 – Frontend Module Template
|
||||
#}
|
||||
|
||||
<!-- indexer::stop -->
|
||||
{% block meilisearch %}
|
||||
<div
|
||||
id="topsearch"
|
||||
class="meilisearch-search"
|
||||
@@ -60,44 +59,10 @@ Contao 5 – Frontend Module Template
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
const CDN_URLS = [
|
||||
'https://cdn.jsdelivr.net/npm/meilisearch@0.39.0/dist/bundles/meilisearch.umd.min.js',
|
||||
'https://unpkg.com/meilisearch@0.39.0/dist/bundles/meilisearch.umd.min.js'
|
||||
];
|
||||
<script type="module">
|
||||
import MeiliSearch from 'https://cdn.jsdelivr.net/npm/meilisearch@latest/dist/bundles/meilisearch.esm.js';
|
||||
|
||||
function loadClient(urls, onDone) {
|
||||
if (typeof MeiliSearch !== 'undefined') {
|
||||
onDone(true, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!urls.length) {
|
||||
onDone(false, 'Alle CDN-Quellen fehlgeschlagen (mögliche CSP-Blockierung von script-src).');
|
||||
return;
|
||||
}
|
||||
|
||||
const url = urls.shift();
|
||||
const script = document.createElement('script');
|
||||
script.src = url;
|
||||
script.async = true;
|
||||
script.crossOrigin = 'anonymous';
|
||||
|
||||
script.onload = () => {
|
||||
if (typeof MeiliSearch !== 'undefined') {
|
||||
onDone(true, null);
|
||||
} else {
|
||||
loadClient(urls, onDone);
|
||||
}
|
||||
};
|
||||
|
||||
script.onerror = () => loadClient(urls, onDone);
|
||||
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
function initSearch() {
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
const wrapper = document.querySelector('.meilisearch-search');
|
||||
if (!wrapper) return;
|
||||
@@ -130,10 +95,6 @@ Contao 5 – Frontend Module Template
|
||||
input.value = '';
|
||||
results.innerHTML = '';
|
||||
clear.classList.add('is-hidden');
|
||||
|
||||
// ✅ WICHTIG: Suchmodus verlassen
|
||||
document.body.classList.remove('search-active');
|
||||
|
||||
input.focus();
|
||||
});
|
||||
|
||||
@@ -255,19 +216,6 @@ Contao 5 – Frontend Module Template
|
||||
results.appendChild(node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
loadClient([...CDN_URLS], (ok, reason) => {
|
||||
if (!ok) {
|
||||
console.error('[Meilisearch] Browser client konnte nicht geladen werden. ' + reason);
|
||||
return;
|
||||
}
|
||||
|
||||
initSearch();
|
||||
});
|
||||
});
|
||||
})();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
<!-- indexer::continue -->
|
||||
|
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 932 B After Width: | Height: | Size: 932 B |
|
Before Width: | Height: | Size: 937 B After Width: | Height: | Size: 937 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@@ -1,259 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Service;
|
||||
|
||||
use Contao\FilesModel;
|
||||
use Contao\StringUtil;
|
||||
use Contao\System;
|
||||
use Doctrine\DBAL\Connection;
|
||||
|
||||
class MeilisearchFileHelper
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Connection $connection,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Zentrale Datei-Verarbeitung
|
||||
*/
|
||||
public function collect(string $url, string $type, int $pageId): void
|
||||
{
|
||||
$this->log('collect() start', [
|
||||
'url' => $url,
|
||||
'type' => $type,
|
||||
'pageId' => $pageId,
|
||||
]);
|
||||
|
||||
// -------------------------------------------------
|
||||
// 1. URL normalisieren
|
||||
// -------------------------------------------------
|
||||
$cleanUrl = strtok($url, '#');
|
||||
$parts = parse_url($cleanUrl);
|
||||
|
||||
if (!$parts) {
|
||||
$this->log('Invalid URL, skip');
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// 2. Externe Datei? → skip
|
||||
// -------------------------------------------------
|
||||
if (!empty($parts['host'])) {
|
||||
$currentRequest = System::getContainer()
|
||||
->get('request_stack')
|
||||
->getCurrentRequest();
|
||||
|
||||
$pageHost = $currentRequest
|
||||
? parse_url($currentRequest->getSchemeAndHttpHost(), PHP_URL_HOST)
|
||||
: null;
|
||||
|
||||
if ($pageHost && $parts['host'] !== $pageHost) {
|
||||
$this->log('External file detected, skip', [
|
||||
'host' => $parts['host'],
|
||||
]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// 3. Pfad-Kandidaten sammeln (ohne Annahmen!)
|
||||
// -------------------------------------------------
|
||||
$query = [];
|
||||
if (!empty($parts['query'])) {
|
||||
parse_str($parts['query'], $query);
|
||||
}
|
||||
|
||||
$pathCandidates = [];
|
||||
|
||||
// direkter Pfad
|
||||
if (!empty($parts['path'])) {
|
||||
$pathCandidates[] = $parts['path'];
|
||||
}
|
||||
|
||||
// Download-Parameter
|
||||
foreach (['file', 'f', 'p'] as $param) {
|
||||
if (!empty($query[$param])) {
|
||||
$pathCandidates[] = $query[$param];
|
||||
}
|
||||
}
|
||||
|
||||
// normalisieren
|
||||
$pathCandidates = array_values(array_unique(array_filter(array_map(
|
||||
static function ($candidate) {
|
||||
$candidate = rawurldecode(html_entity_decode((string) $candidate, ENT_QUOTES));
|
||||
return ltrim($candidate, '/') ?: null;
|
||||
},
|
||||
$pathCandidates
|
||||
))));
|
||||
|
||||
$this->log('Path candidates (normalized)', [
|
||||
'candidates' => $pathCandidates,
|
||||
]);
|
||||
|
||||
// -------------------------------------------------
|
||||
// 4. FilesModel (DBAFS) auflösen → UUID
|
||||
// -------------------------------------------------
|
||||
$fileModel = null;
|
||||
|
||||
foreach ($pathCandidates as $candidate) {
|
||||
|
||||
// 1) direkt
|
||||
$model = FilesModel::findByPath($candidate);
|
||||
if ($model && $model->uuid) {
|
||||
$fileModel = $model;
|
||||
$this->log('Resolved via FilesModel (direct)', [
|
||||
'candidate' => $candidate,
|
||||
'path' => $model->path,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
|
||||
// 2) fallback: files/ davor
|
||||
if (!str_starts_with($candidate, 'files/')) {
|
||||
$model = FilesModel::findByPath('files/' . $candidate);
|
||||
if ($model && $model->uuid) {
|
||||
$fileModel = $model;
|
||||
$this->log('Resolved via FilesModel (files/ prefix)', [
|
||||
'candidate' => $candidate,
|
||||
'path' => $model->path,
|
||||
]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$fileModel) {
|
||||
$this->log('No Contao file model found, skip', [
|
||||
'candidates' => $pathCandidates,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
$normalizedPath = (string) $fileModel->path;
|
||||
$uuidBin = $fileModel->uuid;
|
||||
$uuid = StringUtil::binToUuid($uuidBin);
|
||||
$canonicalUrl = '/' . ltrim($normalizedPath, '/');
|
||||
|
||||
$this->log('UUID resolved', [
|
||||
'path' => $canonicalUrl,
|
||||
'uuid' => $uuid,
|
||||
]);
|
||||
|
||||
// -------------------------------------------------
|
||||
// 5. Datei im Filesystem prüfen
|
||||
// -------------------------------------------------
|
||||
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
|
||||
$abs = $projectDir . '/public/' . $normalizedPath;
|
||||
|
||||
if (!is_file($abs)) {
|
||||
$this->log('Resolved model but file missing on filesystem, skip', [
|
||||
'path' => $normalizedPath,
|
||||
'abs' => $abs,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// 6. Redaktionellen Titel aus tl_files.meta
|
||||
// -------------------------------------------------
|
||||
$title = null;
|
||||
$meta = StringUtil::deserialize($fileModel->meta, true);
|
||||
|
||||
// 1) bevorzugte Sprache (falls vorhanden)
|
||||
$lang = $GLOBALS['TL_LANGUAGE'] ?? null;
|
||||
if ($lang && !empty($meta[$lang]['title'])) {
|
||||
$title = trim((string) $meta[$lang]['title']);
|
||||
}
|
||||
|
||||
// 2) Fallback: erste verfügbare Sprache
|
||||
if ($title === null && is_array($meta)) {
|
||||
foreach ($meta as $langKey => $langMeta) {
|
||||
if (!empty($langMeta['title'])) {
|
||||
$title = trim((string) $langMeta['title']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($title) {
|
||||
$this->log('Title resolved from tl_files', [
|
||||
'title' => $title,
|
||||
]);
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// 7. Datei-Infos
|
||||
// -------------------------------------------------
|
||||
$mtime = filemtime($abs) ?: 0;
|
||||
$checksum = md5($normalizedPath . '|' . $mtime);
|
||||
$now = time();
|
||||
|
||||
// -------------------------------------------------
|
||||
// 8. Upsert über UUID
|
||||
// -------------------------------------------------
|
||||
$existing = $this->connection->fetchAssociative(
|
||||
'SELECT id FROM tl_search_files WHERE uuid = ?',
|
||||
[$uuidBin]
|
||||
);
|
||||
|
||||
if ($existing) {
|
||||
$data = [
|
||||
'tstamp' => $now,
|
||||
'last_seen' => $now,
|
||||
'type' => $type,
|
||||
'url' => $canonicalUrl,
|
||||
'page_id' => $pageId,
|
||||
'file_mtime' => $mtime,
|
||||
'checksum' => $checksum,
|
||||
];
|
||||
|
||||
if ($title !== null) {
|
||||
$data['title'] = $title;
|
||||
}
|
||||
|
||||
$this->connection->update(
|
||||
'tl_search_files',
|
||||
$data,
|
||||
['id' => $existing['id']]
|
||||
);
|
||||
|
||||
$this->log('File updated by UUID', [
|
||||
'uuid' => $uuid,
|
||||
]);
|
||||
} else {
|
||||
$this->connection->insert(
|
||||
'tl_search_files',
|
||||
[
|
||||
'tstamp' => $now,
|
||||
'last_seen' => $now,
|
||||
'type' => $type,
|
||||
'url' => $canonicalUrl,
|
||||
'title' => $title ?? basename($normalizedPath),
|
||||
'page_id' => $pageId,
|
||||
'file_mtime' => $mtime,
|
||||
'checksum' => $checksum,
|
||||
'uuid' => $uuidBin,
|
||||
]
|
||||
);
|
||||
|
||||
$this->log('File inserted by UUID', [
|
||||
'uuid' => $uuid,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->log('collect() end');
|
||||
}
|
||||
|
||||
// -------------------------------------------------
|
||||
// Logging
|
||||
// -------------------------------------------------
|
||||
private function log(string $message, array $context = []): void
|
||||
{
|
||||
$ctx = $context
|
||||
? ' | ' . json_encode($context, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)
|
||||
: '';
|
||||
|
||||
error_log('[ContaoMeilisearch][MeilisearchFileHelper] ' . $message . $ctx);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Service;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\Service;
|
||||
|
||||
use Contao\Config;
|
||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Mummert\ContaoMeilisearchBundle\Service;
|
||||
namespace MummertMedia\ContaoMeilisearchBundle\Service;
|
||||
|
||||
use Contao\Config;
|
||||
use Contao\CoreBundle\Framework\ContaoFramework;
|
||||
|
||||