.vue
page where you need the message cloud search feature, introduce <TUISearch>.Parameter Name | Type | Description |
searchType | String | global: Global search (default) |
| | conversation: Search in conversation |
|
|
| |
import { TUISearch } from "@tencentcloud/chat-uikit-vue";// Global search<TUISearch searchType="global" />// Search in conversation<TUISearch searchType="conversation" />
<TUISearch>
integrated by default. If you prefer not to use the default integration method, you can comment out <TUISearch>
in TUIKit/index.vue
..vue
page where you need the message cloud search feature, introduce <TUISearch>.Parameter Name | Type | Description |
searchType | String | global: Global search |
| | conversation: Search in conversation (default) |
|
|
| |
// The following is just an example path. Replace it with the path of your project.import { TUISearch } from "/TUIKit/components/TUISearch/index.vue";// Global search<TUISearch searchType="global" />// Search in conversation<TUISearch searchType="conversation" />
<TUISearch>
integrated by default. If you prefer not to use the default integration method, you can comment out <TUISearch>
in TUIKit/components/TUIConversation/index.vue
.{"pages": [...,{"path": "TUIKit/components/TUISearch/index","style": {"navigationBarTitleText": "Chat records"}}],...}
uni.navigateTo({url: "/TUIKit/components/TUISearch/index",});
Original "Global Search" message type list | "Global Search" message type list after addition |
| |
src/TUIKit/components/TUISearch/search-type-list.ts
searchMessageTypeList
contains all the definitions in the "Search Message Types" tab. To add search message types not defined in searchMessageTypeList
, follow the structure below to add them in searchMessageTypeList
:[keyName: string]: {key: string; // Specifies the key of the search message type, which must be unique.label: string; // Specifies the label for rendering search message type.value: Array<string>; // Specifies the actual search list for the search message type.};// For example, to search for custom messagesexport const searchMessageTypeList = {...customMessage: {key: "customMessage", // Specifies the key of the search message type, which must be unique.label: "Custom", // Specifies the label for rendering search message type.value: [TUIChatEngine.TYPES.MSG_CUSTOM], // Specifies the actual search list for the search message type.}};
src/TUIKit/locales/zh_cn/TUISearch.ts
and src/TUIKit/locales/en/TUISearch.ts
for translation.searchMessageTypeList
to Global Search Type List or Search in conversation Type List, you just need to add its key
to globalSearchTypeKeys
or conversationSearchTypeKeys
.// For example, to apply the newly defined customMessage to the "Global Search" message type listexport const globalSearchTypeKeys = [..., "customMessage"];// For example, to apply the newly defined customMessage to the "Search in conversation" message type listexport const conversationSearchTypeKeys = [..., "customMessage"];
Original "Global Search" time range list | "Global Search" time range list after addition |
| |
src/TUIKit/components/TUISearch/search-time-list.ts
searchMessageTimeList
contains all definitions in the "Search Time Range" tab. To add search time range types not defined in searchMessageTimeList
, follow the structure below to add them in searchMessageTimeList
:[keyName: string]: {key: string; // Specifies the key of the message search time range, which must be unique.label: string; // Specifies the label for rendering the message search time range.value: {timePosition: number; // Specifies the start position for message search time range. The default value is 0, indicating searching from the current time.timePeriod: number; // Specifies the time range to search backward from timePosition.};};// For example, to search for messages in the time range of "last two days"export const searchMessageTimeList = {...twoDay: {key: "twoDay", // Specifies the key of the message search time range, which must be unique.label: "Two days", // Specifies the label for rendering the message search time range.value: {timePosition: 0, // Specifies the start position for message search time range. The default value is 0, indicating searching from the current time.timePeriod: 2 * oneDay; // Specifies the time range to search backward from timePosition.},},};
src/TUIKit/locales/zh_cn/TUISearch.ts
and src/TUIKit/locales/en/TUISearch.ts
for translation.messageList
returned by the API will be [], and [<5>${messageCount} <5/> records] can be displayed on the UI. If you want to highlight the matched messages, follow the instructions in <7>Specified Search</7> and highlight the returned <9>messageList</9>.messageList
is the matched message.chat.searchCloudMessages(options);
Name | Type | Description |
keywordList | Array | undefined | Specifies the keyword list. Up to 5 keywords are supported. Note: When neither the message sender nor the message type is specified, the keyword list must not be empty; otherwise, it can be empty. |
keywordListMatchType | String | undefined | Specifies the match type of the keyword list. or: Specifies search in the "OR" relationship (default). and: Specifies search in the "AND" relationship. |
senderUserIDList | Array | undefined | Specifies messages sent by the userID. Up to 5 IDs are supported. |
messageTypeList | Array | undefined | Specifies the set of message types to be searched. All types are searched by default. If this parameter is not specified, all supported types of messages ( TencentCloudChat.TYPES.MSG_FACE , TencentCloudChat.TYPES.MSG_GRP_TIP , and TencentCloudChat.TYPES.MSG_GRP_SYS_NOTICE are not supported) are searched.When this parameter is specified, see TencentCloudChat.TYPES for details. |
conversationID | String | undefined | Specifies whether to search for messages in "all conversations" or in the "specified conversation". If this parameter is not specified, all conversations are searched by default. The default value is all conversations. The composition of conversation ID: C2C${userID} (for one-on-one chat)GROUP${groupID} (for group chat)Communities, topics, and live broadcast groups do not support cloud message search. |
timePosition | Number | undefined | Specifies the start time point for search, in the unit of seconds. The default value is 0, indicating searching from the current time. |
timePeriod | Number | undefined | Specifies the range of past time starting from the start time point, in the unit of seconds. The default value is 0, indicating no time limit. The value 24 60 60 indicates the last day. |
cursor | String | undefined | Specifies the start position for each cloud search. Do not specify cursor for the first search. For subsequent searches, fill in the value of cursor returned by the last call to the searchCloudMessages API.Note: During a full search, the cursor's validity period is 2 minutes. |
Promise
Name | Type | Description |
totalCount | Number | In case of search in a specified conversation, the total number of messages that meet the search criteria will be returned. In case of search in all conversations, the total number of conversations containing messages that meet the search criteria will be returned. |
searchResultList | Array | Messages that meet the search criteria are grouped by conversation ID. |
cursor | String | Specifies the cursor needed when continuing to retrieve through the search API. |
searchResultList
is a list containing search result objects, with parameters described as follows:Name | Type | Description |
conversationID | String | conversation ID. |
messageCount | Number | Specifies the total number of messages matching the criteria found in the current conversation. |
messageList | Array | Specifies the list of all messages in the current conversation that meet the search criteria. Note: 1. In case of search in a specified conversation, messageList is the list of all messages in this conversation that meet the search criteria.2. In case of search in all conversations, the number of messages contained in messageList may have the following two possibilities:If the number of matched messages, that is, messageCount , is greater than 1, messageList returned by the API is []. [${messageCount} records] can be displayed on the UI. If you want to highlight the matched messages, see Specified Search and highlight the messageList returned by the API.If the number of matched messages in a conversation equals 1, then messageList is the matched message. |
conversationID
.// Perform full search with specified keywords.// - Search for messages containing 'hello' or 'where are you'let promise = chat.searchCloudMessages({keywordList: ['hello', 'where are you']});promise.then(function(imResponse) {// Messages searched successfully.const { totalCount, cursor, searchResultList } = imResponse.data;console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.for (let i = 0; i < searchResultList.length; i++) {const searchResultItem = searchResultList[i];const { conversationID, messageCount, messageList } = searchResultItem;console.log(conversationID); // Specifies the conversation ID.console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.// In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:// - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.// - If the number of messages matched in a conversation equals 1, then messageList is the matched message.// This message can be displayed on the UI and the matching keywords are highlighted.console.log(messageList);}}).catch(function(imError) {console.error(imError); // Failed to search for messages.});
conversationID
, search by specifying keywords.// Search in a specified conversation by specifying keywords.// - Search for messages containing 'hello' or 'where are you' in the 'GROUPPublic001' conversation.let promise = chat.searchCloudMessages({keywordList: ['hello', 'where are you'],conversationID: 'GROUPPublic001'});promise.then(function(imResponse) {// Messages searched successfully.const { totalCount, cursor, searchResultList } = imResponse.data;console.log(totalCount); // Specifies the total number of messages that meet the search criteria.console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.console.log(searchResultList); // Specifies message search results of the current conversation.const { conversationID, messageCount, messageList } = searchResultList[0];console.log(conversationID); // Specifies the conversation ID.console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.console.log(messageList); // Specifies the list of all messages in the current conversation that meet the search criteria.}).catch(function(imError); {console.error(imError); // Failed to search for messages.});
description
parameter. Keywords with description
are supported.messageTypeList
as TencentCloudChat.TYPES.MSG_CUSTOM
for categorized search, which will search for all custom messages.// Perform full search with specified keywords and message types.// - Search for messages of type 'custom message', where the description contains 'hello' or 'where are you.'let promise = chat.searchCloudMessages({keywordList: ['hello', 'where are you'],messageTypeList: [TencentCloudChat.TYPES.MSG_CUSTOM],});promise.then(function(imResponse) {// Messages searched successfully.const { totalCount, cursor, searchResultList } = imResponse.data;console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.for (let i = 0; i < searchResultList.length; i++) {const searchResultItem = searchResultList[i];const { conversationID, messageCount, messageList } = searchResultItem;console.log(conversationID); // Specifies the conversation ID.console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.// In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:// - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.// - If the number of messages matched in a conversation equals 1, then messageList is the matched message.// This message can be displayed on the UI and the matching keywords are highlighted.console.log(messageList);}}).catch(function(imError) {console.error(imError); // Failed to search for messages.});
createFileMessage
is called to create a file message with the fileName
parameter, fileName
will act as the content to be searched for and match the search keywords.fileName
, and the UI usually displays a thumbnail or duration. Specifying keywordList
for search is ineffective in this case.messageTypeList
as TencentCloudChat.TYPES.MSG_IMAGE
/TencentCloudChat.TYPES.MSG_AUDIO
/TencentCloudChat.TYPES.MSG_FILE
for categorized search, which will reveal all messages of the specified types.// Perform full search by only specifying the message sender and message types (when the sender and message types are specified, the keyword list can be empty).// - Search for messages from 'user1' or 'user2', and messages of type 'Image Message', 'Voice Message', or 'File Message'.let promise = chat.searchCloudMessages({senderUserIDList: ['user1', 'user2'],messageTypeList: [TencentCloudChat.TYPES.MSG_IMAGE,TencentCloudChat.TYPES.MSG_AUDIO,TencentCloudChat.TYPES.MSG_FILE],});promise.then(function(imResponse) {// Messages searched successfully.const { totalCount, cursor, searchResultList } = imResponse.data;console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.for (let i = 0; i < searchResultList.length; i++) {const searchResultItem = searchResultList[i];const { conversationID, messageCount, messageList } = searchResultItem;console.log(conversationID); // Specifies the conversation ID.console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.// In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:// - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.// - If the number of messages matched in a conversation equals 1, then messageList is the matched message.// This message can be displayed on the UI and the matching keywords are highlighted.console.log(messageList);}}).catch(function(imError) {console.error(imError); // Failed to search for messages.});
latitude
, longitude
, description
and keywords are supported.messageTypeList
as TencentCloudChat.TYPES.MSG_LOCATION
for categorized search, which will search for all geographical location messages.// Perform full search with specified keywords and message types.// - Search for messages of type 'Geographical Location', where the latitude, longitude, and description contains 'hello' or 'where are you'.let promise = chat.searchCloudMessages({keywordList: ['hello', 'where are you'],messageTypeList: [TencentCloudChat.TYPES.MSG_LOCATION],});promise.then(function(imResponse) {// Messages searched successfully.const { totalCount, cursor, searchResultList } = imResponse.data;console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.for (let i = 0; i < searchResultList.length; i++) {const searchResultItem = searchResultList[i];const { conversationID, messageCount, messageList } = searchResultItem;console.log(conversationID); // Specifies the conversation ID.console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.// In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:// - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.// -If the number of messages matched in a conversation equals 1, then messageList is the matched message.// This message can be displayed on the UI and the matching keywords are highlighted.console.log(messageList);}}).catch(function(imError) {console.error(imError); // Failed to search for messages.});
title
or abstractList
parameters. Keywords title
and abstractList
are supported.messageTypeList
as TencentCloudChat.TYPES.MSG_MERGER
for categorized search, which will search for all merger messages.// Perform full search with specified keywords and message types.// - Search for message types marked as ‘Merger Message’, and messages containing ‘hello’ or ‘where are you?’ in their title or abstractList.let promise = chat.searchCloudMessages({keywordList: ['hello', 'where are you'],messageTypeList: [TencentCloudChat.TYPES.MSG_MERGER],});promise.then(function(imResponse) {// Messages searched successfully.const { totalCount, cursor, searchResultList } = imResponse.data;console.log(totalCount); // Specifies the total number of conversations containing messages that meet the search criteria.console.log(cursor); // Specifies the start position for the next cloud search. If this parameter is not specified, the search results have been fully retrieved.console.log(searchResultList); // Messages that meet the search criteria are grouped by conversation ID, and the grouped results are returned by page.for (let i = 0; i < searchResultList.length; i++) {const searchResultItem = searchResultList[i];const { conversationID, messageCount, messageList } = searchResultItem;console.log(conversationID); // Specifies the conversation ID.console.log(messageCount); // Specifies the total number of messages that meet the criteria found in the current conversation.// In case of search in [all conversations], the number of messages loaded in messageList has the following two possibilities:// - If the number of messages matched in a conversation is greater than 1, then messageList will be empty. "messageCount records" can be displayed on the UI.// - If the number of messages matched in a conversation equals 1, then messageList is the matched message.// This message can be displayed on the UI and the matching keywords are highlighted.console.log(messageList);}}).catch(function(imError) {console.error(imError); // Failed to search for messages.});
Was this page helpful?