Add Index Listener

This commit is contained in:
Jürgen Mummert
2025-12-22 16:59:08 +01:00
parent 8a704e965f
commit 99d974af17
+32 -8
View File
@@ -5,6 +5,9 @@ namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use MummertMedia\ContaoMeilisearchBundle\Service\SearchDataProvider;
/**
* IndexPage Listener for Contao search index
*/
class IndexPageListener
{
public function __construct(
@@ -12,23 +15,44 @@ class IndexPageListener
) {}
/**
* This hook is executed for every indexed document
*
* @Hook("indexPage")
*/
public function onIndexPage(string $content, array &$data, array &$set): void
{
// 🔍 DEBUG MUSS jetzt feuern
file_put_contents(
TL_ROOT . '/var/logs/meili-debug.log',
json_encode($set, JSON_PRETTY_PRINT) . "\n\n",
FILE_APPEND
);
// ---------------------------------------------------------------------
// DEBUG: prove that the hook is executed (CLI + Frontend safe)
// ---------------------------------------------------------------------
error_log('[MEILI] onIndexPage fired');
// log basic context
error_log('[MEILI] type=' . ($set['type'] ?? 'NULL'));
error_log('[MEILI] set=' . json_encode($set, JSON_UNESCAPED_SLASHES));
// ---------------------------------------------------------------------
// Fetch search data (priority + keywords)
// ---------------------------------------------------------------------
$searchData = $this->dataProvider->getSearchData($set);
// log provider result
error_log('[MEILI] provider result=' . json_encode($searchData));
if ($searchData === null) {
error_log('[MEILI] no search data resolved');
return;
}
$data['priority'] = $searchData['priority'];
$data['keywords'] = $searchData['keywords'];
// ---------------------------------------------------------------------
// Write into tl_search (this array IS the DB record)
// ---------------------------------------------------------------------
$data['priority'] = (int) $searchData['priority'];
$data['keywords'] = (string) $searchData['keywords'];
// final confirmation
error_log('[MEILI] tl_search updated: priority='
. $data['priority']
. ' keywords="' . $data['keywords'] . '"'
);
}
}