Browse SDKs · React Native
Platform
SDKsReact Native

Search messages

Search locally synchronized message records by keywords, message types, sender, and time ranges using the OpenIM React Native SDK.

Copy

Search locally synchronized message records across multiple criteria such as keywords, message types, senders, and timestamps:

const result = await OpenIMSDK.searchLocalMessages({
  conversationID,
  keywordList: ['release'],
  messageTypeList: [MessageType.TextMessage],
  pageIndex: 1,
  count: 20,
});

Parameters

Supply one or more search keywords in keywordList. For standard search input bars, pass trimmed, non-empty keyword strings.

ParameterTypeRequiredDescription
conversationIDstringNoScope search to a specific conversation ID. Pass an empty string "" to execute a global search across all conversations.
keywordListstring[]YesArray of keyword strings to search for.
keywordListMatchTypenumberNoMultiple keyword matching strategy: 0 matches any keyword (OR); 1 requires all keywords to match (AND). Defaults to 0.
senderUserIDListstring[]NoArray of sender user IDs to restrict search results to messages sent by these users.
messageTypeListMessageType[]NoArray of message types (e.g., text, pictures); defaults to common chat message types.
searchTimePositionnumberNoSearch time window endpoint (Unix timestamp in seconds).
searchTimePeriodnumberNoDuration in seconds to search backward from searchTimePosition.
pageIndexnumberNoPagination page index, starting at 1.
countnumberNoMaximum number of matching message items per page.

Return value

A resolved Promise returns a SearchMessageResult object:

FieldTypeDescription
totalCountnumberTotal number of messages matching the search criteria.
searchResultItemsSearchMessageResultItem[]Search result items categorized and grouped by conversation.

Each SearchMessageResultItem contains conversation metadata and an array of matched messages messageList: MessageItem[]. When a user taps a matching message in the search results, use Load message context to navigate to the message and reconstruct surrounding conversation context. Reset pageIndex to 1 whenever query keywords or filter criteria change.