perf: 优化全文搜索

This commit is contained in:
kuaifan 2025-04-17 12:43:18 +08:00
parent f61e7caf2b
commit dbf42c51a4
3 changed files with 21 additions and 21 deletions

View File

@ -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';
/**

View File

@ -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
{

View File

@ -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)
];
}