Skip to main content

Module message_search

Module message_search 

Source
Available on crate feature experimental-search only.
Expand description

Messages search facilities and high-level helpers to perform searches across one or multiple rooms.

These helpers expose the results as Streams of pages, lazily fetching the next page from the underlying index as the stream is polled. Use the StreamExt and TryStreamExt combinators (next, try_concat, take, …) to consume them.

§Examples

§Searching within a single room

Use Room::search_messages to get a stream of pages of (score, event_id) pairs, or Room::search_messages_events to load the full TimelineEvents.

let mut stream = Box::pin(room.search_messages("hello world".to_owned()));

while let Some(page) = stream.next().await {
    for (score, event_id) in page? {
        println!("Found event {event_id} (score: {score})");
    }
}

§Searching across all joined rooms

Use Client::search_messages to create a GlobalSearchBuilder. Optionally restrict the working set to DM rooms (or non-DM rooms) before calling GlobalSearchBuilder::build to get a stream of pages of results, sorted by relevance score across all rooms. Use GlobalSearchBuilder::build_events to load full TimelineEvents instead of plain event IDs.

// Search only in DM rooms.
let mut stream = Box::pin(
    client
        .search_messages("hello world".to_owned())
        .only_dm_rooms()
        .await?
        .build_events(),
);

while let Some(page) = stream.next().await {
    for (room_id, event) in page? {
        println!(
            "Found event in room {room_id} with timestamp: {:?}",
            event.timestamp
        );
    }
}

Structs§

GlobalSearchBuilder
A builder for a global search Stream that allows configuring the initial working set of rooms to search in.

Enums§

SearchError
An error that can occur while searching messages, using the high-level search helpers provided by this module.