SDKsReact Native
Search messages
OpenIM React Native SDK guide for search messages.
Use searchLocalMessages() to search messages already synchronized to the current account's local store.
const result = await OpenIMSDK.searchLocalMessages({
conversationID,
keywordList: ['release'],
messageTypeList: [MessageType.TextMessage],
pageIndex: 1,
count: 20,
});Parameters
keywordList can contain one or more keywords. A search field typically supplies one keyword after trimming surrounding whitespace and removing empty values.
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Conversation to search. |
keywordList | string[] | Yes | Keywords to search for. |
keywordListMatchType | number | No | Match mode for multiple keywords: 0 matches any keyword (OR), and 1 requires all keywords (AND). Omitted values use 0. |
senderUserIDList | string[] | No | Restrict results to messages sent by these users. |
messageTypeList | MessageType[] | No | Restrict results to the specified message types, such as text and mention messages. |
searchTimePosition | number | No | Search end position as a Unix timestamp in seconds. |
searchTimePeriod | number | No | Search range backward from searchTimePosition, in seconds. |
pageIndex | number | No | Result page, starting at 1. |
count | number | No | Number of messages per page. |
Return value
The call returns SearchMessageResult:
| Field | Type | Description |
|---|---|---|
totalCount | number | Number of messages matching the current conditions. |
searchResultItems | SearchMessageResultItem[] | Results organized by conversation. |
Each SearchMessageResultItem contains conversation information and messageList. When keywords or filters change, restart from page one so results from different conditions are not mixed. To load messages around a hit, see Load message context.
Was this page helpful?