diff --git a/app/Console/Commands/SyncDialogUserMsgToZincSearch.php b/app/Console/Commands/SyncDialogUserMsgToZincSearch.php index 3dc6ea31e..acef0e30b 100644 --- a/app/Console/Commands/SyncDialogUserMsgToZincSearch.php +++ b/app/Console/Commands/SyncDialogUserMsgToZincSearch.php @@ -19,7 +19,7 @@ class SyncDialogUserMsgToZincSearch extends Command * --c: 清除索引 */ - protected $signature = 'zinc:sync-dialog-user-msg {--f} {--i} {--c} {--batch=500}'; + protected $signature = 'zinc:sync-dialog-user-msg {--f} {--i} {--c} {--batch=1000}'; protected $description = '同步聊天会话用户和消息到 ZincSearch'; /** diff --git a/app/Module/ZincSearch/ZincSearchKeyValue.php b/app/Module/ZincSearch/ZincSearchKeyValue.php index c1482e4f2..2a56b3d00 100644 --- a/app/Module/ZincSearch/ZincSearchKeyValue.php +++ b/app/Module/ZincSearch/ZincSearchKeyValue.php @@ -11,19 +11,19 @@ use App\Module\Base; * 使用方法: * * 1. 基本操作 - * - 设置键值: ZincSearchValue::set('site_name', '我的网站'); - * - 设置复杂数据: ZincSearchValue::set('site_config', ['logo' => 'logo.png', 'theme' => 'dark']); - * - 合并现有数据: ZincSearchValue::set('site_config', ['footer' => '版权所有'], true); - * - 获取键值: $siteName = ZincSearchValue::get('site_name'); - * - 获取键值带默认值: $theme = ZincSearchValue::get('theme', 'light'); - * - 删除键值: ZincSearchValue::delete('temporary_data'); + * - 设置键值: ZincSearchKeyValue::set('site_name', '我的网站'); + * - 设置复杂数据: ZincSearchKeyValue::set('site_config', ['logo' => 'logo.png', 'theme' => 'dark']); + * - 合并现有数据: ZincSearchKeyValue::set('site_config', ['footer' => '版权所有'], true); + * - 获取键值: $siteName = ZincSearchKeyValue::get('site_name'); + * - 获取键值带默认值: $theme = ZincSearchKeyValue::get('theme', 'light'); + * - 删除键值: ZincSearchKeyValue::delete('temporary_data'); * * 2. 批量操作 - * - 批量设置: ZincSearchValue::batchSet(['user_count' => 100, 'active_users' => 50]); - * - 批量获取: $stats = ZincSearchValue::batchGet(['user_count', 'active_users']); + * - 批量设置: ZincSearchKeyValue::batchSet(['user_count' => 100, 'active_users' => 50]); + * - 批量获取: $stats = ZincSearchKeyValue::batchGet(['user_count', 'active_users']); * * 3. 其他操作 - * - 清空所有数据: ZincSearchValue::clear(); + * - 清空所有数据: ZincSearchKeyValue::clear(); */ class ZincSearchKeyValue { diff --git a/app/Module/ZincSearch/ZincSearchUserMsg.php b/app/Module/ZincSearch/ZincSearchUserMsg.php index f814595fd..67f959de2 100644 --- a/app/Module/ZincSearch/ZincSearchUserMsg.php +++ b/app/Module/ZincSearch/ZincSearchUserMsg.php @@ -74,9 +74,9 @@ class ZincSearchUserMsg 'key' => ['type' => 'text', 'index' => true], 'bot' => ['type' => 'numeric', 'index' => true], - // 关联字段 - ZincSearch不支持父子文档,使用引用字段代替 - 'parent_id' => ['type' => 'keyword', 'index' => true], - 'doc_type' => ['type' => 'keyword', 'index' => true] // dialog_user 或 dialog_msg + // 关联字段 + '_join_type' => ['type' => 'keyword', 'index' => true], + '_join_key' => ['type' => 'keyword', 'index' => true], ] ]; @@ -168,7 +168,7 @@ class ZincSearchUserMsg */ public static function generateUserDocId(WebSocketDialogUser $dialogUser): string { - return "user_{$dialogUser->userid}_dialog_{$dialogUser->dialog_id}"; + return "dialog_{$dialogUser->dialog_id}_user_{$dialogUser->userid}"; } /** @@ -192,8 +192,8 @@ class ZincSearchUserMsg 'hide' => $dialogUser->hide ?: 0, 'color' => $dialogUser->color, - 'doc_type' => 'dialog_user', - 'parent_id' => '' // 用户文档没有父文档 + '_join_type' => 'dialog_user', + '_join_key' => '' // 用户文档没有父文档 ]; } @@ -261,7 +261,7 @@ class ZincSearchUserMsg $searchParams = [ 'search_type' => 'term', 'query' => [ - 'field' => 'parent_id', + 'field' => '_join_key', 'term' => $docId ], 'from' => 0, @@ -297,9 +297,9 @@ class ZincSearchUserMsg * @param string $userid * @return string */ - public static function generateMsgParentId(WebSocketDialogMsg $dialogMsg, string $userid): string + public static function generateMsgJoinKey(WebSocketDialogMsg $dialogMsg, string $userid): string { - return "user_{$userid}_dialog_{$dialogMsg->dialog_id}"; + return "dialog_{$dialogMsg->dialog_id}_user_{$userid}"; } /** @@ -334,8 +334,8 @@ class ZincSearchUserMsg 'key' => $dialogMsg->key, 'bot' => $dialogMsg->bot ? 1 : 0, - 'doc_type' => 'dialog_msg', - 'parent_id' => self::generateMsgParentId($dialogMsg, $userid) + '_join_type' => 'dialog_msg', + '_join_key' => self::generateMsgJoinKey($dialogMsg, $userid) ]; }