MessageSearchParam. When searching for messages, the SDK will execute different search logics based on this object's settings.MessageSearchParam are as follows:Parameter | Meaning | Description |
msg_search_param_keyword_array | Keyword list | It can contain up to five keywords. When the message sender and the message type are not specified, the keyword list must be set; in other cases, it can be left empty. |
msg_search_param_keyword_list_match_type | Match type of the keyword list | You can set it to search with "OR" logic or "AND" logic. The values are TIMKeywordListMatchType_Or and TIMKeywordListMatchType_And, respectively. By default, it uses "OR" logic. |
msg_search_param_send_identifier_array | Search for messages sent by a specified userID | Up to five are supported. |
msg_search_param_message_type_array | Set of the message types to be searched for | Leaving it empty means searching for all supported types of messages ( kTIMElem_Face and kTIMElem_GroupTips are not searchable). Refer to TIMElemType for other types. |
msg_search_param_conv_id | Search "all conversations" or "a specified conversation" | If msg_search_param_conv_id is empty, search all sessions; if msg_search_param_conv_id is not empty, search the specified session. |
msg_search_param_search_time_position | Start time for the search | The default is 0 (search from now). UTC Timestamp, in seconds. |
msg_search_param_search_time_period | A past period of time starting from the start time | The default is 0 (unlimited time range). 24 x 60 x 60 represents the past day, in seconds. |
msg_search_param_search_count | Number of search results | Number of searches, support up to 100. |
msg_search_param_search_cursor | Search cursor | Starting position, fill in an empty character string for the first time, and fill in the msg_search_result_search_cursor from the last MessageSearchResult returned for subsequent pulls. |
MessageSearchResult. The parameters are as described below:Parameter | Meaning | Description |
msg_search_result_total_count | Total number of the search result items | If a specific session is searched, the total number of messages that meet the search criteria will be returned; If all sessions are searched, the total number of sessions containing messages that meet the search criteria will be returned. |
msg_search_result_item_array | Search results list | If a specific session is searched, the returned result list will only include results from that session; If all sessions are searched, messages that meet the search criteria will be grouped by session ID, and the grouping results will be returned paginated. |
msg_search_result_search_cursor | Continue pulling the cursor | Cursor required for continuation while calling the search API |
messageSearchResultItems is a list containing MessageSearchResultItemobjects, with the parameters described as follows:Parameter | Meaning | Description |
msg_search_result_item_conv_id | Session ID | - |
msg_search_result_item_total_message_count | Number of messages | The total number of messages matching the criteria found in the current session. |
msg_search_result_item_message_array | List of messages that meet the search criteria | If a specific session is searched, msg_search_result_item_message_array contains a list of all messages meeting the search criteria within this session.If all sessions are searched, the number of messages contained in msg_search_result_item_message_array may have the following two possibilities:If the number of messages matched in a session is > 1, then msg_search_result_item_message_array is empty, and you can display "{msg_search_result_item_total_message_count} relevant records" on the UI.If the number of messages matched in a session = 1, then msg_search_result_item_message_array is the matched message, and you can display it on the UI and highlight the search keywords. |
MsgSearchCloudMessages to search for messages.msg_search_param_conv_id in MessageSearchParam unset or set to empty.List<string> keywordList = new List<string>();keywordList.add("abc");keywordList.add("123");MessageSearchParam searchParam = new MessageSearchParam{msg_search_param_keyword_array = keywordList,msg_search_param_conv_id = "",msg_search_param_search_count = 20,msg_search_param_search_time_position = 0,msg_search_param_search_time_period = 600,msg_search_param_search_cursor = ""};TencentIMSDK.MsgSearchCloudMessages(searchParam, (int code, string desc, MessageSearchResult result, string user_data)=>{// Process the async logic});
MsgSearchCloudMessages to search for messages.List<string> keywordList = new List<string>();keywordList.add("abc");keywordList.add("123");MessageSearchParam searchParam = new MessageSearchParam{msg_search_param_keyword_array = keywordList,msg_search_param_conv_id = "c2c_user1",msg_search_param_search_count = 20,msg_search_param_search_time_position = 0,msg_search_param_search_time_period = 600,msg_search_param_search_cursor = ""};TencentIMSDK.MsgSearchCloudMessages(searchParam, (int code, string desc, MessageSearchResult result, string user_data)=>{// Process the async logic});
Figure 1. Chat Record | Figure 2. More Chat Record | Figure 3. Messages in the specified session |
![]() | ![]() | ![]() |
MessageSearchParammsg_search_param_conv_id set to null or "" , indicates searching messages from all sessions.msg_search_param_search_cursor set to "", indicates searching for the latest data.msg_search_param_search_count set to 3, indicates returning the number of the most recent sessions, typically showing 3 entries on the UI.MessageSearchResultmsg_search_result_total_count indicates the number of all sessions to which the matched messages belong.msg_search_result_item_array list contains the last 3 sessions (as per the msg_search_param_search_count parameter). msg_search_result_item_total_message_count of MessageSearchResultItem indicates the total number of messages found in the current session;messageList will be empty. You can display "4 related chat records" on the UI, where 4 represents the messageCount.messageList is the message that matches. You can display the message content on the UI and highlight the search keyword, for example, "test" in the Typical Use Cases for the Search image.List<string> keywordList = new List<string>();keywordList.add("test");MessageSearchParam searchParam = new MessageSearchParam{msg_search_param_keyword_array = keywordList,msg_search_param_conv_id = "",msg_search_param_search_count = 3,msg_search_param_search_cursor = ""};TencentIMSDK.MsgSearchCloudMessages(searchParam, (int code, string desc, MessageSearchResult result, string user_data)=>{// Total number of matched sessions to which messages belongint totalCount = result.msg_search_result_total_count;// Last three messages classified by sessionList<MessageSearchResultItem> resultItemList = result.msg_search_result_item_array;foreach (var resultItem in resultItemList) {// Session IDstring conversationID = resultItem.msg_search_result_item_conv_id;// Total number of messages matching the sessionint totalMessageCount = resultItem.msg_search_result_item_total_message_count;// Message list: If totalMessageCount > 1, this list is empty; if totalMessageCount = 1, this list Element (XML) is this messageList<Message> messageList = resultItem.msg_search_result_item_message_array;}});
MessageSearchParam can be set as follows:msg_search_param_search_count = 10, msg_search_param_search_cursor = "". Call MsgSearchCloudMessages to obtain the message search results, parse and display them on the homepage, and obtain the total number of sessions msg_search_result_total_count and the cursor for the next request msg_search_result_search_cursor from the result callback.msg_search_result_search_cursor from the previous request results.......// Record the search cursorstring searchCursor = "";......void searchConversation(string cursor) {List<string> keywordList = new List<string>();keywordList.add("test");MessageSearchParam searchParam = new MessageSearchParam{msg_search_param_keyword_array = keywordList,msg_search_param_conv_id = "",msg_search_param_search_count = 10,msg_search_param_search_cursor = cursor};TencentIMSDK.MsgSearchCloudMessages(searchParam, (int code, string desc, MessageSearchResult result, string user_data)=>{// Total number of matched sessions to which messages belongint totalCount = result.msg_search_result_total_count;// Cursor for the next pagesearchCursor = result.msg_search_result_search_cursor;// Messages on the current pageList<MessageSearchResultItem> resultItemList = result.msg_search_result_item_array;foreach (var resultItem in resultItemList) {// Session IDstring conversationID = resultItem.msg_search_result_item_conv_id;// Total number of messages matching the sessionint totalMessageCount = resultItem.msg_search_result_item_total_message_count;// Message list: If totalMessageCount > 1, this list is empty; if totalMessageCount = 1, this list Element (XML) is this messageList<Message> messageList = resultItem.msg_search_result_item_message_array;}});}// Load the next pagevoid loadMore() {searchConversation(searchCursor);}
MessageSearchParam settings can be referred to as follows:MessageSearchParam's msg_search_param_conv_id as the session ID you are searching for.msg_search_param_search_count = 10, msg_search_param_search_cursor = "". Call MsgSearchCloudMessages to obtain the message search results, parse and display them on the homepage, and obtain the total number of sessions msg_search_result_total_count and the cursor for the next page msg_search_result_search_cursor from the result callback.msg_search_param_search_cursor to the return value from the callback of the previous call.MessageSearchResult:msg_search_result_total_count indicates the total number of messages matched in that session.msg_search_result_item_array list contains only the results for that session. In the list, msg_search_result_item_total_message_count of MessageSearchResultItem is the number of messages on that page, and msg_search_result_item_message_array is the list of messages on that page.msg_search_result_search_cursor represents the starting cursor for the next page search.......// Record the search cursorstring searchCursor = "";......void searchMessage(String cursor) {List<string> keywordList = new List<string>();keywordList.add("test");MessageSearchParam searchParam = new MessageSearchParam{msg_search_param_keyword_array = keywordList,msg_search_param_conv_id = "conversationID",msg_search_param_search_count = 10,msg_search_param_search_cursor = cursor};TencentIMSDK.MsgSearchCloudMessages(searchParam, (int code, string desc, MessageSearchResult result, string user_data)=>{// Total number of messages matching the sessionint totalMessageCount = result.msg_search_result_total_count;// Cursor for the next pagesearchCursor = result.msg_search_result_search_cursor;// Messages on the current pageList<MessageSearchResultItem> resultItemList = result.msg_search_result_item_array;foreach (var resultItem in resultItemList) {// Session IDstring conversationID = resultItem.msg_search_result_item_conv_id;// The number of messages on the current pageint totalMessageCount = resultItem.msg_search_result_item_total_message_count;// List of messages on the current pageList<Message> messageList = resultItem.msg_search_result_item_message_array;}});}// Load the next pagevoid loadMore() {searchMessage(searchCursor);}
custom_elem_desc parameter when creating custom messages.offline_push_config_desc parameter, your custom messages will also have offline push and the notification bar will display the content of that parameter. If you don't need offline push, you can control this by setting the offline_push_config_flag field in the message_offline_push_config parameter to kTIMOfflinePushFlag_NoPush when sending the message.offline_push_config_desc in the message_offline_push_config parameter to set the push content differently.file_elem_file_name parameter when creating a file message, file_elem_file_name will be used as the content of the file message to be searched and matched with the search keyword. If file_elem_file_name is not set, the SDK will automatically extract the file name from file_elem_file_path as the search content. Both file_elem_file_name and file_elem_file_path information is saved to the local device and server, and can be searched after pulling relevant information on a new device.file_elem_file_name, and the interface usually displays a thumbnail or duration, making the specification of msg_search_param_keyword_array ineffective for searches. If you wish to search for such messages, you can specify msg_search_param_message_type_array as kTIMElem_Image/kTIMElem_Sound/kTIMElem_Video for categorized searches, which will then retrieve all messages of the specified types.Was this page helpful?
You can also Contact sales or Submit a Ticket for help.
Help us improve! Rate your documentation experience in 5 mins.
Feedback