Extend system search to include local e-conomic customer index fields, synonym expansion (e.g., rabat -> discount), and enhanced entity matching. Update OpenAPI spec, unit tests, and cron sync tasks accordingly.

This commit is contained in:
Jeppe Bundgaard
2026-03-13 00:59:40 +01:00
parent efc5906974
commit 5be31bee1c
5 changed files with 326 additions and 33 deletions
+33 -3
View File
@@ -4,6 +4,7 @@
use classes\backup_store;
use classes\economic;
use classes\system_search_cache;
use classes\system_search_economic_customer_index;
use classes\xlvask;
use classes\slack as Slack;
use classes\email as Email;
@@ -63,6 +64,12 @@ $cron_tasks = [
'next_run' => 0,
'function' => 'SyncUserEconomicCustomerDetails',
],
'SyncSystemSearchEconomicCustomerIndex' => [
'interval' => 900, // 15 minutes
'last_run' => 0,
'next_run' => 0,
'function' => 'SyncSystemSearchEconomicCustomerIndex',
],
'backup' => [
'interval' => 43200, // 12 hours
'last_run' => 0,
@@ -134,9 +141,28 @@ function SyncUserEconomicCustomerDiscounts(): void
function SyncUserEconomicCustomerDetails(): void
{
$users_o = new users_o();
$users_o->clearAllUsersEconomicCustomerDetailsFromCache();
//$users_o->syncAllUsersEconomicCustomerDetails();
try {
$users_o = new users_o();
$users_o->clearAllUsersEconomicCustomerDetailsFromCache();
$users_o->syncAllUsersEconomicCustomerDetails();
$stats = system_search_economic_customer_index::refreshIndex(false);
echo "[" . date('Y-m-d H:i:s') . "][CRON] Refreshed e-conomic customer snapshots and search index. Upserted: "
. (int)($stats['upserted'] ?? 0) . "\n";
} catch (Throwable $e) {
warn('SyncUserEconomicCustomerDetails failed: ' . $e->getMessage());
}
}
function SyncSystemSearchEconomicCustomerIndex(): void
{
try {
$stats = system_search_economic_customer_index::refreshIndex(false);
echo "[" . date('Y-m-d H:i:s') . "][CRON] Synced system search e-conomic customer index. Processed: "
. (int)($stats['processed'] ?? 0) . ", upserted: " . (int)($stats['upserted'] ?? 0)
. ", deleted: " . (int)($stats['deleted'] ?? 0) . "\n";
} catch (Throwable $e) {
warn('SyncSystemSearchEconomicCustomerIndex failed: ' . $e->getMessage());
}
}
/**
@@ -178,12 +204,16 @@ function SystemSearchCacheMaintenanceCron(): void
if ($rebuildRequest !== null) {
system_search_cache::clearQueryCaches();
system_search_cache::clearIntentCaches();
system_search_economic_customer_index::refreshIndex(false);
echo "[" . date('Y-m-d H:i:s') . "][CRON] System search cache rebuild handled. Scope: " . ($rebuildRequest['scope'] ?? 'all') . "\n";
return;
}
if (!empty($dirtyTables)) {
system_search_cache::clearQueryCaches();
if (in_array('users', $dirtyTables, true)) {
system_search_economic_customer_index::refreshIndex(false);
}
echo "[" . date('Y-m-d H:i:s') . "][CRON] System search query cache invalidated for dirty tables: " . implode(', ', $dirtyTables) . "\n";
}
} catch (Throwable $e) {