Search

Last Edit: Feb 02 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>
                    

// Search with default filter where the current user is a member of channels.
// Default pagination is 20 messages.
Client.shared.search(query: "supercalifragilisticexpialidocious")
    .subscribe(onNext: { messages in
        print(messages)
    })
    .disposed(by: disposeBag)

// A custom filter and the next page for the results.
Client.shared.search(filter: filter, query: "supercalifragilisticexpialidocious", pagination: .limit(20) + .offset(20))
    .subscribe(onNext: { messages in
        print(messages)
    })
    .disposed(by: disposeBag)
                    

client.searchMessages(
  SearchMessagesRequest(
      Filters.`in`("members", listOf("john")),
      "supercalifragilisticexpialidocious")
      .withLimit(2)
      .withOffset(0),
  object : SearchMessagesCallback {
      override fun onSuccess(response: SearchMessagesResponse?) {
          
      }

      override fun onError(errMsg: String?, errCode: Int) {
     
      }
})
                    

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.