Browse SDKs · React Native
SDKsReact Native

Search messages

OpenIM React Native SDK guide for search messages.

Copy

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.

ParameterTypeRequiredDescription
conversationIDstringYesConversation to search.
keywordListstring[]YesKeywords to search for.
keywordListMatchTypenumberNoMatch mode for multiple keywords: 0 matches any keyword (OR), and 1 requires all keywords (AND). Omitted values use 0.
senderUserIDListstring[]NoRestrict results to messages sent by these users.
messageTypeListMessageType[]NoRestrict results to the specified message types, such as text and mention messages.
searchTimePositionnumberNoSearch end position as a Unix timestamp in seconds.
searchTimePeriodnumberNoSearch range backward from searchTimePosition, in seconds.
pageIndexnumberNoResult page, starting at 1.
countnumberNoNumber of messages per page.

Return value

The call returns SearchMessageResult:

FieldTypeDescription
totalCountnumberNumber of messages matching the current conditions.
searchResultItemsSearchMessageResultItem[]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.