curl -X POST "http://localhost:5001/plugins/wk.plugin.search/usersearch" \
-H "Content-Type: application/json" \
-d '{
"uid": "user123",
"payload": {
"content": "北京"
},
"payload_types": [1, 2],
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": ["payload.content"]
}'
const searchParams = {
uid: "user123",
payload: {
content: "北京"
},
payload_types: [1, 2],
channel_type: 2,
limit: 10,
page: 1,
highlights: ["payload.content"]
};
const response = await fetch('http://localhost:5001/plugins/wk.plugin.search/usersearch', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(searchParams)
});
const data = await response.json();
console.log(data);
import requests
search_params = {
"uid": "user123",
"payload": {
"content": "北京"
},
"payload_types": [1, 2],
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": ["payload.content"]
}
response = requests.post(
'http://localhost:5001/plugins/wk.plugin.search/usersearch',
json=search_params
)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
searchParams := map[string]interface{}{
"uid": "user123",
"payload": map[string]interface{}{
"content": "北京",
},
"payload_types": []int{1, 2},
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": []string{"payload.content"},
}
jsonData, _ := json.Marshal(searchParams)
resp, err := http.Post(
"http://localhost:5001/plugins/wk.plugin.search/usersearch",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"total": 25,
"limit": 10,
"page": 1,
"messages": [
{
"message_id": 1234,
"message_idstr": "1234",
"message_seq": 1,
"client_msg_no": "djzdfdfdf",
"from_uid": "u1",
"channel_id": "g1",
"channel_type": 2,
"payload": {
"type": 1,
"content": "你是<mark>北京</mark>大学的吗"
},
"topic": "",
"timestamp": 762834
},
{
"message_id": 1235,
"message_idstr": "1235",
"message_seq": 2,
"client_msg_no": "djzdfdfde",
"from_uid": "u2",
"channel_id": "g1",
"channel_type": 2,
"payload": {
"type": 1,
"content": "我在<mark>北京</mark>工作"
},
"topic": "",
"timestamp": 762835
}
]
}
消息管理
用户消息搜索
搜索属于当前用户的所有消息,支持多维度搜索和中文分词
POST
/
plugins
/
wk.plugin.search
/
usersearch
curl -X POST "http://localhost:5001/plugins/wk.plugin.search/usersearch" \
-H "Content-Type: application/json" \
-d '{
"uid": "user123",
"payload": {
"content": "北京"
},
"payload_types": [1, 2],
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": ["payload.content"]
}'
const searchParams = {
uid: "user123",
payload: {
content: "北京"
},
payload_types: [1, 2],
channel_type: 2,
limit: 10,
page: 1,
highlights: ["payload.content"]
};
const response = await fetch('http://localhost:5001/plugins/wk.plugin.search/usersearch', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(searchParams)
});
const data = await response.json();
console.log(data);
import requests
search_params = {
"uid": "user123",
"payload": {
"content": "北京"
},
"payload_types": [1, 2],
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": ["payload.content"]
}
response = requests.post(
'http://localhost:5001/plugins/wk.plugin.search/usersearch',
json=search_params
)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
searchParams := map[string]interface{}{
"uid": "user123",
"payload": map[string]interface{}{
"content": "北京",
},
"payload_types": []int{1, 2},
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": []string{"payload.content"},
}
jsonData, _ := json.Marshal(searchParams)
resp, err := http.Post(
"http://localhost:5001/plugins/wk.plugin.search/usersearch",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"total": 25,
"limit": 10,
"page": 1,
"messages": [
{
"message_id": 1234,
"message_idstr": "1234",
"message_seq": 1,
"client_msg_no": "djzdfdfdf",
"from_uid": "u1",
"channel_id": "g1",
"channel_type": 2,
"payload": {
"type": 1,
"content": "你是<mark>北京</mark>大学的吗"
},
"topic": "",
"timestamp": 762834
},
{
"message_id": 1235,
"message_idstr": "1235",
"message_seq": 2,
"client_msg_no": "djzdfdfde",
"from_uid": "u2",
"channel_id": "g1",
"channel_type": 2,
"payload": {
"type": 1,
"content": "我在<mark>北京</mark>工作"
},
"topic": "",
"timestamp": 762835
}
]
}
概述
搜索属于当前用户的所有消息,支持多维度搜索和中文分词功能。- 需要 WuKongIM v2.1.3-20250210 或以上版本
- 需要安装
wk.plugin.search插件 - 插件使用文档:插件使用指南
请求体
string
必填
当前用户 UID(限制搜索指定用户的消息)
string
发送者 UID
string
频道 ID,指定频道后只搜索此频道内的消息
integer
频道类型
1- 个人频道2- 群组频道
string
根据 topic 搜索
integer
查询限制数量,默认 10
integer
页码,分页使用,默认为 1
integer
消息时间(开始),Unix 时间戳
integer
消息时间(结束,结果包含 end_time),Unix 时间戳
curl -X POST "http://localhost:5001/plugins/wk.plugin.search/usersearch" \
-H "Content-Type: application/json" \
-d '{
"uid": "user123",
"payload": {
"content": "北京"
},
"payload_types": [1, 2],
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": ["payload.content"]
}'
const searchParams = {
uid: "user123",
payload: {
content: "北京"
},
payload_types: [1, 2],
channel_type: 2,
limit: 10,
page: 1,
highlights: ["payload.content"]
};
const response = await fetch('http://localhost:5001/plugins/wk.plugin.search/usersearch', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(searchParams)
});
const data = await response.json();
console.log(data);
import requests
search_params = {
"uid": "user123",
"payload": {
"content": "北京"
},
"payload_types": [1, 2],
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": ["payload.content"]
}
response = requests.post(
'http://localhost:5001/plugins/wk.plugin.search/usersearch',
json=search_params
)
result = response.json()
print(result)
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
searchParams := map[string]interface{}{
"uid": "user123",
"payload": map[string]interface{}{
"content": "北京",
},
"payload_types": []int{1, 2},
"channel_type": 2,
"limit": 10,
"page": 1,
"highlights": []string{"payload.content"},
}
jsonData, _ := json.Marshal(searchParams)
resp, err := http.Post(
"http://localhost:5001/plugins/wk.plugin.search/usersearch",
"application/json",
bytes.NewBuffer(jsonData),
)
if err != nil {
panic(err)
}
defer resp.Body.Close()
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
fmt.Printf("%+v\n", result)
}
{
"total": 25,
"limit": 10,
"page": 1,
"messages": [
{
"message_id": 1234,
"message_idstr": "1234",
"message_seq": 1,
"client_msg_no": "djzdfdfdf",
"from_uid": "u1",
"channel_id": "g1",
"channel_type": 2,
"payload": {
"type": 1,
"content": "你是<mark>北京</mark>大学的吗"
},
"topic": "",
"timestamp": 762834
},
{
"message_id": 1235,
"message_idstr": "1235",
"message_seq": 2,
"client_msg_no": "djzdfdfde",
"from_uid": "u2",
"channel_id": "g1",
"channel_type": 2,
"payload": {
"type": 1,
"content": "我在<mark>北京</mark>工作"
},
"topic": "",
"timestamp": 762835
}
]
}
响应字段
integer
必填
消息总数量
integer
必填
查询数量限制
integer
必填
当前页码
array
必填
状态码
| 状态码 | 说明 |
|---|---|
| 200 | 搜索成功 |
| 400 | 请求参数错误 |
| 403 | 没有搜索权限 |
| 500 | 服务器内部错误 |
搜索功能特性
中文分词搜索
支持中文分词,能够智能识别中文词汇进行搜索。 示例:- 搜索 “北京大学” 可以匹配包含 “北京” 或 “大学” 的消息
- 支持模糊匹配和精确匹配
多维度搜索
支持多个维度的组合搜索:- 内容搜索:通过
payload.content搜索消息内容 - 类型搜索:通过
payload_types限制消息类型 - 用户搜索:通过
from_uid搜索特定用户的消息 - 频道搜索:通过
channel_id搜索特定频道的消息 - 时间搜索:通过
start_time和end_time限制时间范围 - 主题搜索:通过
topic搜索特定主题的消息
高亮显示
通过highlights 参数可以指定需要高亮显示的字段,搜索结果中匹配的关键词会被 <mark> 标签包围。
示例:
{
"payload": {
"content": "北京"
},
"highlights": ["payload.content"]
}
{
"payload": {
"content": "你是<mark>北京</mark>大学的吗"
}
}
使用场景
聊天记录搜索
- 关键词搜索:用户搜索聊天记录中的关键词
- 用户消息:搜索特定用户发送的消息
- 群组消息:在特定群组中搜索消息
内容管理
- 消息审核:搜索包含特定内容的消息
- 数据分析:分析用户消息内容和行为
- 合规检查:检查是否包含敏感内容
⌘I

