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§
- Global
Search Builder - A builder for a global search
Streamthat allows configuring the initial working set of rooms to search in.
Enums§
- Search
Error - An error that can occur while searching messages, using the high-level search helpers provided by this module.