Search

LAST EDIT Apr 08 2021

Message search is built-in to the chat API. You can enable and/or disable the search indexing on a per channel type . 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'”:

1
2
3
4
5
6
7
const filters = { members: { $in: ['john'] } }; 
 
const search = await client.search( 
   filters, 
   'supercalifragilisticexpialidocious', 
   { limit: 2, offset: 0 }, 
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int offset = 0; 
int limit = 10; 
 
FilterObject channelFilter = Filters.in("members", Arrays.asList("john")); 
FilterObject messageFilter = Filters.autocomplete("text", "supercalifragilisticexpialidocious"); 
 
client.searchMessages( 
        new SearchMessagesRequest( 
                offset, 
                limit, 
                channelFilter, 
                messageFilter 
        ) 
).enqueue(result -> { 
    if (result.isSuccess()) { 
        List<Message> messages = result.data(); 
    } else { 
        // Handle result.error() 
    } 
});
1
// coming soon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
client.searchMessages( 
    SearchMessagesRequest( 
        offset = 0, 
        limit = 10, 
        channelFilter = Filters.`in`("members", listOf("john")), 
        messageFilter = Filters.autocomplete("text", "supercalifragilisticexpialidocious") 
    ) 
).enqueue { result -> 
    if (result.isSuccess) { 
        val messages: List<Message> = result.data() 
    } else { 
        // Handle result.error() 
    } 
}
1
2
3
4
5
6
7
$filters = [ 'type' => 'messaging' , 'members' => [ '$in' => ['jenny'] ]]; 
 
$response = $client->search( 
	$filters, 
	'Hey', 
	['limit' => 2, 'offset' => 0] 
);
1
2
3
4
5
6
7
8
filters = { "type": "messaging", "members": { "$in": ["john"] } }; 
 
results = client.search( 
   filters, 
   'supercalifragilisticexpialidocious', 
   limit=2, 
   offset=0, 
);
1
2
3
4
5
6
7
8
final search = await client.search( 
   members: { '\$in': ['john'] }, 
   'supercalifragilisticexpialidocious', 
    pagination: PaginationParams( 
            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.

Additionally, this endpoint can be used to search for messages that have attachments.

1
2
3
4
5
6
// Search by Attachment 
const searchByAttachment = async () => { 
  const messageFilters = { attachments: { $exists: true } }; 
  const response = await channel.search(messageFilters); 
  return response; 
};
1
2
3
4
5
6
7
8
9
10
11
12
channelClient.getMessagesWithAttachments( 
    offset = 0, 
    limit = 10, 
    type = "image", 
).enqueue { result -> 
    if (result.isSuccess) { 
        // These messages will contain at least one of the desired  
        // type of attachment, but not necessarily all of their  
        // attachments will have the specified type 
        val messages: List<Message> = result.data() 
    } 
}
1
2
3
4
5
6
7
8
9
10
11
int offset = 0; 
int limit = 10; 
String type = "image"; 
channelClient.getMessagesWithAttachments(offset, limit, type).enqueue(result -> { 
    if (result.isSuccess()) { 
        // These messages will contain at least one of the desired 
        // type of attachment, but not necessarily all of their 
        // attachments will have the specified type 
        List<Message> messages = result.data(); 
    } 
});
1
2
3
4
5
6
7
8
// Search file of type videos 
  final response = await channel.search(messageFilter: { 
        'attachments.type': { 
          r'$in': ['video'], 
        }, 
      }, 
  ); 
  return response;