Skip to main content
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": "Beijing"
    },
    "payload_types": [1, 2],
    "channel_type": 2,
    "limit": 10,
    "page": 1,
    "highlights": ["payload.content"]
  }'
{
  "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": "Are you from <mark>Beijing</mark> University?"
      },
      "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": "I work in <mark>Beijing</mark>"
      },
      "topic": "",
      "timestamp": 762835
    }
  ]
}

Overview

Search all messages belonging to the current user, supporting multi-dimensional search and Chinese word segmentation functionality.
  • Requires WuKongIM v2.1.3-20250210 or above
  • Requires installation of wk.plugin.search plugin
  • Plugin usage documentation: Plugin Development Guide

Request Body

Required Parameters

uid
string
required
Current user UID (restricts search to specified user’s messages)

Optional Parameters

payload
object
Message payload, supports searching custom fields
payload_types
array
Message type search
payload_types[]
integer
Message type value
from_uid
string
Sender UID
channel_id
string
Channel ID, when specified, only search messages within this channel
channel_type
integer
Channel type
  • 1 - Personal channel
  • 2 - Group channel
topic
string
Search by topic
limit
integer
Query limit, default 10
page
integer
Page number for pagination, default 1
start_time
integer
Message time (start), Unix timestamp
end_time
integer
Message time (end, result includes end_time), Unix timestamp
highlights
array
Keyword fields that need highlighting
highlights[]
string
Field name, e.g., “payload.content”
curl -X POST "http://localhost:5001/plugins/wk.plugin.search/usersearch" \
  -H "Content-Type: application/json" \
  -d '{
    "uid": "user123",
    "payload": {
      "content": "Beijing"
    },
    "payload_types": [1, 2],
    "channel_type": 2,
    "limit": 10,
    "page": 1,
    "highlights": ["payload.content"]
  }'
{
  "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": "Are you from <mark>Beijing</mark> University?"
      },
      "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": "I work in <mark>Beijing</mark>"
      },
      "topic": "",
      "timestamp": 762835
    }
  ]
}

Response Fields

total
integer
required
Total number of messages
limit
integer
required
Query limit
page
integer
required
Current page number
messages
array
required
Message list

Status Codes

Status CodeDescription
200Search successful
400Request parameter error
403No search permission
500Internal server error

Search Features

Chinese Word Segmentation

Supports Chinese word segmentation, intelligently recognizing Chinese vocabulary for search. Examples:
  • Searching “Beijing University” can match messages containing “Beijing” or “University”
  • Supports both fuzzy matching and exact matching
Supports combined search across multiple dimensions:
  1. Content Search: Search message content through payload.content
  2. Type Search: Limit message types through payload_types
  3. User Search: Search specific user’s messages through from_uid
  4. Channel Search: Search specific channel’s messages through channel_id
  5. Time Search: Limit time range through start_time and end_time
  6. Topic Search: Search specific topic messages through topic

Highlighting

Through the highlights parameter, you can specify fields that need highlighting. Matching keywords in search results will be surrounded by <mark> tags. Example:
{
  "payload": {
    "content": "Beijing"
  },
  "highlights": ["payload.content"]
}
Return result:
{
  "payload": {
    "content": "Are you from <mark>Beijing</mark> University?"
  }
}

Use Cases

  • Keyword Search: Users search for keywords in chat history
  • User Messages: Search messages sent by specific users
  • Group Messages: Search messages within specific groups

Content Management

  • Message Moderation: Search messages containing specific content
  • Data Analysis: Analyze user message content and behavior
  • Compliance Check: Check for sensitive content

Advanced Search Examples

Search by Time Range:
const timeRangeSearch = {
  uid: "user123",
  payload: { content: "project" },
  start_time: 1640995200, // 2022-01-01
  end_time: 1672531200,   // 2023-01-01
  limit: 20
};
Search by Message Type:
const typeSearch = {
  uid: "user123",
  payload_types: [1, 2], // Text and image messages only
  channel_id: "group123",
  limit: 50
};
Search with Multiple Criteria:
const complexSearch = {
  uid: "user123",
  payload: { content: "meeting" },
  from_uid: "manager123",
  channel_type: 2,
  topic: "work",
  highlights: ["payload.content"],
  limit: 10
};

Best Practices

  1. Pagination: Use appropriate page size to avoid performance issues
  2. Time Limits: Set reasonable time ranges for better performance
  3. Keyword Optimization: Use specific keywords for more accurate results
  4. Result Caching: Cache search results for frequently used queries
  5. Permission Check: Ensure users can only search their own messages
  6. Rate Limiting: Implement rate limiting to prevent search abuse