-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathcommands.rs
More file actions
96 lines (86 loc) · 2.55 KB
/
commands.rs
File metadata and controls
96 lines (86 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use crate::{SearchDocument, SearchFilters, SearchResult, TantivyPluginExt};
#[tauri::command]
#[specta::specta]
pub(crate) async fn ping<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<(), String> {
app.tantivy().ping().map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn init<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<(), String> {
app.tantivy().init().await.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn add_document<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
doc: SearchDocument,
) -> Result<(), String> {
app.tantivy()
.add_document(doc)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn update_document<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
doc: SearchDocument,
) -> Result<(), String> {
app.tantivy()
.update_document(doc)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn delete_document<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
id: String,
) -> Result<(), String> {
app.tantivy()
.delete_document(id)
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn commit<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<(), String> {
app.tantivy().commit().await.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn search<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
query: String,
filters: Option<SearchFilters>,
limit: Option<usize>,
) -> Result<SearchResult, String> {
app.tantivy()
.search(query, filters, limit.unwrap_or(100))
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn search_fuzzy<R: tauri::Runtime>(
app: tauri::AppHandle<R>,
query: String,
filters: Option<SearchFilters>,
limit: Option<usize>,
distance: Option<u8>,
) -> Result<SearchResult, String> {
app.tantivy()
.search_fuzzy(query, filters, limit.unwrap_or(100), distance.unwrap_or(1))
.await
.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn clear<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<(), String> {
app.tantivy().clear().await.map_err(|e| e.to_string())
}
#[tauri::command]
#[specta::specta]
pub(crate) async fn count<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<u64, String> {
app.tantivy().count().await.map_err(|e| e.to_string())
}