🌐 AI搜索 & 代理 主页
Skip to content

Commit c41340b

Browse files
authored
Dont crash the dashboard if search index is not built (#1018)
1 parent b04bede commit c41340b

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

pgml-dashboard/src/utils/markdown.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,24 @@ impl SearchIndex {
11931193
}
11941194

11951195
pub fn open() -> tantivy::Result<SearchIndex> {
1196-
let index = tantivy::Index::open_in_dir(&Self::path())?;
1196+
let path = Self::path();
1197+
1198+
if !path.exists() {
1199+
std::fs::create_dir(&path)
1200+
.expect("failed to create search_index directory, is the filesystem writable?");
1201+
}
1202+
1203+
let index = match tantivy::Index::open_in_dir(&path) {
1204+
Ok(index) => index,
1205+
Err(err) => {
1206+
warn!(
1207+
"Failed to open Tantivy index in '{}', creating an empty one, error: {}",
1208+
path.display(),
1209+
err
1210+
);
1211+
Index::create_in_dir(&path, Self::schema())?
1212+
}
1213+
};
11971214

11981215
let reader = index.reader_builder().try_into()?;
11991216

0 commit comments

Comments
 (0)