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 {
1193
1193
}
1194
1194
1195
1195
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
+ } ;
1197
1214
1198
1215
let reader = index. reader_builder ( ) . try_into ( ) ?;
1199
1216
You can’t perform that action at this time.
0 commit comments