Search

Last Edit: May 05 2020

Message search is built-in to the chat API. You can enable and/or disable the search indexing on a per chat type basis. The command shown below selects the channels in which John is a member. Next, it searches the messages in those channels for the keyword “'supercalifragilisticexpialidocious'”:


const filters = { members: { $in: ['john'] } };

const search = await client.search(
   filters,
   'supercalifragilisticexpialidocious',
   { limit: 2, offset: 0 },
);
                    

final ArrayList<string> searchUsersList = new ArrayList&lt;&gt;();
searchUsersList.add("john");

final FilterObject filter = Filters.in("members", searchUsersList);

SearchMessagesRequest searchMessagesRequest = new SearchMessagesRequest(filter,
        "supercalifragilisticexpialidocious")
        .withLimit(2)
        .withOffset(0);

client.searchMessages(searchMessagesRequest,
    new SearchMessagesCallback() {
        @Override
        public void onSuccess(SearchMessagesResponse response) {

        }

        @Override
        public void onError(String errMsg, int errCode) {

        }
});</string>
                    

let query = SearchQuery(filter: .in("members", ["john"]),
                        query: "supercalifragilisticexpialidocious",
                        pagination: [.channelsPageSize])
Client.shared.search(query: query) { (result) in
    // handle result
}
                    

val offset = 0
val limit = 10
val query = "supercalifragilisticexpialidocious"

client.searchMessages(
    SearchMessagesRequest(
        query,
        offset, limit,
        Filters.`in`("members", listOf("john"))
    )
).enqueue {
    val messages = it.data()
}
                    

$filters = [ 'type' => 'messaging' , 'members' => [ '$in' => ['jenny'] ]];

$response = $client->search(
	$filters,
	'Hey',
	['limit' => 2, 'offset' => 0]
);
                    

Pagination works via the standard limit and offset parameters. The first argument, filter, uses a MongoDB style query expression.

We do not run MongoDB on the backend, so only a subset of the standard MongoDB filters are supported.