Add Index Listener
This commit is contained in:
@@ -5,6 +5,9 @@ namespace MummertMedia\ContaoMeilisearchBundle\EventListener;
|
|||||||
use Contao\CoreBundle\ServiceAnnotation\Hook;
|
use Contao\CoreBundle\ServiceAnnotation\Hook;
|
||||||
use MummertMedia\ContaoMeilisearchBundle\Service\SearchDataProvider;
|
use MummertMedia\ContaoMeilisearchBundle\Service\SearchDataProvider;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* IndexPage Listener for Contao search index
|
||||||
|
*/
|
||||||
class IndexPageListener
|
class IndexPageListener
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -12,23 +15,44 @@ class IndexPageListener
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* This hook is executed for every indexed document
|
||||||
|
*
|
||||||
* @Hook("indexPage")
|
* @Hook("indexPage")
|
||||||
*/
|
*/
|
||||||
public function onIndexPage(string $content, array &$data, array &$set): void
|
public function onIndexPage(string $content, array &$data, array &$set): void
|
||||||
{
|
{
|
||||||
// 🔍 DEBUG – MUSS jetzt feuern
|
// ---------------------------------------------------------------------
|
||||||
file_put_contents(
|
// DEBUG: prove that the hook is executed (CLI + Frontend safe)
|
||||||
TL_ROOT . '/var/logs/meili-debug.log',
|
// ---------------------------------------------------------------------
|
||||||
json_encode($set, JSON_PRETTY_PRINT) . "\n\n",
|
error_log('[MEILI] onIndexPage fired');
|
||||||
FILE_APPEND
|
|
||||||
);
|
|
||||||
|
|
||||||
|
// 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);
|
$searchData = $this->dataProvider->getSearchData($set);
|
||||||
|
|
||||||
|
// log provider result
|
||||||
|
error_log('[MEILI] provider result=' . json_encode($searchData));
|
||||||
|
|
||||||
if ($searchData === null) {
|
if ($searchData === null) {
|
||||||
|
error_log('[MEILI] no search data resolved');
|
||||||
return;
|
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'] . '"'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user