Skip to content

Commit 992774b

Browse files
Add the matrix-sdk-search crate
A new crate with a basic API for a creating, populating and searching a room message index. Signed-off-by: Shrey Patel [email protected]
1 parent 9d90a92 commit 992774b

File tree

11 files changed

+1167
-15
lines changed

11 files changed

+1167
-15
lines changed

Cargo.lock

Lines changed: 430 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ matrix-sdk-sqlite = { path = "crates/matrix-sdk-sqlite", version = "0.13.0", def
118118
matrix-sdk-store-encryption = { path = "crates/matrix-sdk-store-encryption", version = "0.13.0" }
119119
matrix-sdk-test = { path = "testing/matrix-sdk-test", version = "0.13.0" }
120120
matrix-sdk-ui = { path = "crates/matrix-sdk-ui", version = "0.13.0", default-features = false }
121+
matrix-sdk-search = { path = "crates/matrix-sdk-search", version = "0.13.0" }
121122

122123
[workspace.lints.rust]
123124
rust_2018_idioms = "warn"

crates/matrix-sdk-base/src/response_processors/state_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub mod sync {
160160
Ok(())
161161
}
162162

163-
/// Dispatch a [`RoomMemberEventContent>`] state event.
163+
/// Dispatch a [`RoomMemberEventContent`] state event.
164164
async fn dispatch_room_member<U>(
165165
context: &mut Context,
166166
room_id: &RoomId,

crates/matrix-sdk-search/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
authors = ["Shrey Patel <[email protected]>"]
3+
description = "The search component to build a Matrix client library."
4+
edition = "2024"
5+
homepage = "https://github.com/matrix-org/matrix-rust-sdk"
6+
license = "Apache-2.0"
7+
name = "matrix-sdk-search"
8+
readme = "README.md"
9+
repository = "https://github.com/matrix-org/matrix-rust-sdk"
10+
rust-version.workspace = true
11+
version = "0.13.0"
12+
13+
[package.metadata.docs.rs]
14+
all-features = true
15+
rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"]
16+
17+
[dependencies]
18+
tantivy = "0.24.2"
19+
ruma = { workspace = true , features = [
20+
"client-api-c",
21+
"events",
22+
"rand",
23+
"unstable-msc1767"
24+
] }
25+
tracing = { workspace = true, features = ["attributes"] }
26+
thiserror.workspace = true
27+
matrix-sdk-test = { workspace = true, optional = true }
28+
29+
[dev-dependencies]
30+
matrix-sdk-test.workspace = true
31+
32+
[lints]
33+
workspace = true
34+

crates/matrix-sdk-search/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# matrix-sdk-search

crates/matrix-sdk-search/src/error.rs

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
// Copyright 2024 The Matrix.org Foundation C.I.C.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//! The event cache is an abstraction layer, sitting between the Rust SDK and a
16+
//! final client, that acts as a global observer of all the rooms, gathering and
17+
//! inferring some extra useful information about each room. In particular, this
18+
//! doesn't require subscribing to a specific room to get access to this
19+
//! information.
20+
//!
21+
//! It's intended to be fast, robust and easy to maintain, having learned from
22+
//! previous endeavours at implementing middle to high level features elsewhere
23+
//! in the SDK, notably in the UI's Timeline object.
24+
//!
25+
//! See the [github issue](https://github.com/matrix-org/matrix-rust-sdk/issues/3058) for more
26+
//! details about the historical reasons that led us to start writing this.
27+
28+
use tantivy::{
29+
directory::error::OpenDirectoryError as TantivyOpenDirectoryError,
30+
query::QueryParserError as TantivyQueryParserError,
31+
};
32+
use thiserror::Error;
33+
34+
/// Internal representation of Search Index errors.
35+
#[derive(Error, Debug)]
36+
pub enum IndexError {
37+
/// Tantivy Error
38+
#[error(transparent)]
39+
TantivyError(tantivy::TantivyError),
40+
41+
/// Open Directory Error
42+
#[error(transparent)]
43+
OpenDirectoryError(TantivyOpenDirectoryError),
44+
45+
/// Query Parse Error
46+
#[error(transparent)]
47+
QueryParserError(TantivyQueryParserError),
48+
49+
/// Schema Error
50+
#[error(transparent)]
51+
IndexSchemaError(IndexSchemaError),
52+
53+
/// Write Error
54+
#[error(transparent)]
55+
IndexWriteError(IndexWriteError),
56+
57+
/// Search Error
58+
#[error(transparent)]
59+
IndexSearchError(IndexSearchError),
60+
61+
/// Add Event Error
62+
#[error("Failed to add event to index")]
63+
EventNotAdded,
64+
65+
/// Message Type Error
66+
#[error("Message type not supported")]
67+
MessageTypeNotSupported,
68+
69+
/// Indexing Redacted Message Error
70+
#[error("Cannot index redacted message")]
71+
CannotIndexRedactedMessage,
72+
73+
/// Indexing Empty Message Error
74+
#[error("Cannot index empty message")]
75+
EmptyMessage,
76+
77+
/// IO error
78+
#[error(transparent)]
79+
IO(std::io::Error),
80+
}
81+
82+
impl From<tantivy::TantivyError> for IndexError {
83+
fn from(err: tantivy::TantivyError) -> IndexError {
84+
IndexError::TantivyError(err)
85+
}
86+
}
87+
88+
impl From<TantivyOpenDirectoryError> for IndexError {
89+
fn from(err: TantivyOpenDirectoryError) -> IndexError {
90+
IndexError::OpenDirectoryError(err)
91+
}
92+
}
93+
94+
impl From<TantivyQueryParserError> for IndexError {
95+
fn from(err: TantivyQueryParserError) -> IndexError {
96+
IndexError::QueryParserError(err)
97+
}
98+
}
99+
100+
impl From<IndexSchemaError> for IndexError {
101+
fn from(err: IndexSchemaError) -> IndexError {
102+
IndexError::IndexSchemaError(err)
103+
}
104+
}
105+
106+
impl From<IndexWriteError> for IndexError {
107+
fn from(err: IndexWriteError) -> IndexError {
108+
IndexError::IndexWriteError(err)
109+
}
110+
}
111+
112+
impl From<IndexSearchError> for IndexError {
113+
fn from(err: IndexSearchError) -> IndexError {
114+
IndexError::IndexSearchError(err)
115+
}
116+
}
117+
118+
impl From<std::io::Error> for IndexError {
119+
fn from(err: std::io::Error) -> IndexError {
120+
IndexError::IO(err)
121+
}
122+
}
123+
124+
/// Internal representation of Schema errors.
125+
#[derive(Error, Debug)]
126+
pub enum IndexSchemaError {
127+
/// Tantivy Error
128+
#[error(transparent)]
129+
TantivyError(tantivy::TantivyError),
130+
}
131+
132+
impl From<tantivy::TantivyError> for IndexSchemaError {
133+
fn from(err: tantivy::TantivyError) -> IndexSchemaError {
134+
IndexSchemaError::TantivyError(err)
135+
}
136+
}
137+
138+
/// Internal representation of Writer errors.
139+
#[derive(Error, Debug)]
140+
pub enum IndexWriteError {
141+
/// Tantivy Error
142+
#[error(transparent)]
143+
TantivyError(tantivy::TantivyError),
144+
}
145+
146+
impl From<tantivy::TantivyError> for IndexWriteError {
147+
fn from(err: tantivy::TantivyError) -> IndexWriteError {
148+
IndexWriteError::TantivyError(err)
149+
}
150+
}
151+
152+
/// Internal representation of Search errors.
153+
#[derive(Error, Debug)]
154+
pub enum IndexSearchError {
155+
/// Tantivy Error
156+
#[error(transparent)]
157+
TantivyError(tantivy::TantivyError),
158+
}
159+
160+
impl From<tantivy::TantivyError> for IndexSearchError {
161+
fn from(err: tantivy::TantivyError) -> IndexSearchError {
162+
IndexSearchError::TantivyError(err)
163+
}
164+
}

0 commit comments

Comments
 (0)