Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Message
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Search messages by a keyword

Message search allows you to retrieve a list of messages that contain a search query or a specified keyword in group channels by implementing MessageSearchQuery. The query retrieves a list of messages that contain a search term and meet the optional parameter values set in the MessageSearchQueryParams class.

You can create the query instance in two ways. First, you can do so with the default values.

val query = SendbirdChat.createMessageSearchQuery(MessageSearchQueryParams(KEYWORD))

Or, you can create an instance by changing those values to your preference.

val query = SendbirdChat.createMessageSearchQuery(
    MessageSearchQueryParams("Sendbird").apply {
        limit = 10
        // ...
    }
)

Then, the query retrieves a list of match results. Calling the next() method returns the next page of the results.

query.next { messages, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

Use the hasNext method to see if there is a next page.

query.hasNext

Use the isLoading method to see if the search results are loading.

query.isLoading

MessageSearchQueryParams

You can build the query class using the following parameters, which allows you to add various search options.

Parameter nameTypeDescription

keyword

string

Specifies the search term.

* If the specified search term includes special characters or punctuations, it returns an error.

channelUrl

string

Specifies the URL of the target channel.

channelCustomType

string

Specifies the custom channel type.

limit

int

Specifies the number of messages to return per page. Acceptable values are 1 to 99, inclusive. (Default: 20)

exactMatch

boolean

Determines whether to search for messages that exactly match the search term. If set to false, it returns partially matched messages that contain the search term. (Default: false)

messageTimestampFrom

long

Restricts the search scope to the messages sent after the specified value in Unix milliseconds format. This includes the messages sent exactly on the timestamp. (Default: 0)

messageTimestampTo

long

Restricts the search scope to the messages sent before the specified value in Unix milliseconds format. This includes the messages sent exactly on the timestamp. (Default: Long.MAX_VALUE)

order

enum

Determines which field the results are sorted by. Acceptable values are the following:
- SCORE (default): the search relevance score.
- TIMESTAMP: the time when a message was created. (Default: SCORE)

reverse

boolean

Determines whether to sort the results in reverse order. If set to false, they will be sorted in descending order. (Default: false)