7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | # `matrix-sdk-search` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | This crate implements a searchable index for messages in a Matrix client. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | ## Usage |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | The recommended way to use this crate is to include `matrix-sdk` as a dependency |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | in your `Cargo.toml` file with the `experimental-search` feature flag turned on. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | ## Stand-alone usage |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | Constructing a `matrix_sdk_search::index::RoomIndex` is done with the |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | `matrix_sdk_search::index::builder::RoomIndexBuilder`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | ```rust |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | use std::path::PathBuf; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | use matrix_sdk_search::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | error::IndexError, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | index::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | RoomIndex, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | builder::RoomIndexBuilder, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | }, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | use ruma::RoomId; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | fn create_index(path: PathBuf, room_id: &RoomId) -> Result<RoomIndex, IndexError> { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | RoomIndexBuilder::new_on_disk(path, room_id).unencrypted().build() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | ``` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | The search crate accepts index operations through |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | `matrix_sdk_search::index::RoomIndex::execute()` which takes a |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | `matrix_sdk_search::index::RoomIndexOperation`. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | ```rust |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | use matrix_sdk_search::index::{ |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | RoomIndex, RoomIndexOperation, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | builder::RoomIndexBuilder |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | use ruma::events::room::message::OriginalSyncRoomMessageEvent; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 42 | async fn add_event(index: &mut RoomIndex, event: OriginalSyncRoomMessageEvent) { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 43 | index.execute(RoomIndexOperation::Add(event)); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 44 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 45 | ``` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 46 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 47 | Some method(s) for creating these operations will need to be implemented. There |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 48 | is an example of handling `ruma::events::AnySyncTimelineEvents` in |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 49 | `matrix-sdk::search_index`. |