🌐 AI搜索 & 代理 主页
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Dont crash the app if search index is not built
  • Loading branch information
levkk committed Sep 16, 2023
commit f7f83e88c2b6f691693550552bf0e602fec0fe9c
19 changes: 18 additions & 1 deletion pgml-dashboard/src/utils/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,24 @@ impl SearchIndex {
}

pub fn open() -> tantivy::Result<SearchIndex> {
let index = tantivy::Index::open_in_dir(&Self::path())?;
let path = Self::path();

if !path.exists() {
std::fs::create_dir(Self::path())
.expect("failed to create search_index directory, is the filesystem writable?");
}

let index = match tantivy::Index::open_in_dir(&Self::path()) {
Ok(index) => index,
Err(err) => {
warn!(
"Failed to open Tantivy index in '{}', creating an empty one, error: {}",
path.display(),
err
);
Index::create_in_dir(&Self::path(), Self::schema())?
}
};

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

Expand Down