Files
matrix-rust-sdk/crates/matrix-sdk-search
ragebreaker b081654c51 fix(search): Create key dirs if they don't exist. (#5992)
The issue is related to the encrypt_store_dir fn where, when creating
the key file, it doesn't ensure that the parent directory exists first.
It might be not optimal for the user of the crate to ensure in an non
hacky manner, as the sdk iterates through most of its directories
internally. Have a test to verify it, which can be removed later (if
being merged)

Needs a review, might not be the optimal solution as this is my first pr
with the crate and am not that familiar with it (although do use it in
one of my apps).
2026-01-07 11:07:36 +01:00
..

matrix-sdk-search

This crate implements a searchable index for messages in a Matrix client.

Usage

The recommended way to use this crate is to include matrix-sdk as a dependency in your Cargo.toml file with the experimental-search feature flag turned on.

Stand-alone usage

Constructing a matrix_sdk_search::index::RoomIndex is done with the matrix_sdk_search::index::builder::RoomIndexBuilder.

use std::path::PathBuf;
use matrix_sdk_search::{
    error::IndexError,
    index::{
        RoomIndex,
        builder::RoomIndexBuilder,
    },
};
use ruma::RoomId;

fn create_index(path: PathBuf, room_id: &RoomId) -> Result<RoomIndex, IndexError> {
    RoomIndexBuilder::new_on_disk(path, room_id).unencrypted().build()
}

The search crate accepts index operations through matrix_sdk_search::index::RoomIndex::execute() which takes a matrix_sdk_search::index::RoomIndexOperation.

use matrix_sdk_search::index::{
    RoomIndex, RoomIndexOperation,
    builder::RoomIndexBuilder
};
use ruma::events::room::message::OriginalSyncRoomMessageEvent;

async fn add_event(index: &mut RoomIndex, event: OriginalSyncRoomMessageEvent) {
    index.execute(RoomIndexOperation::Add(event));
}

Some method(s) for creating these operations will need to be implemented. There is an example of handling ruma::events::AnySyncTimelineEvents in matrix-sdk::search_index.