File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments