@@ -1080,8 +1080,6 @@ async fn main() -> Result<()> {
10801080 total_emails_all_archives
10811081 ) ;
10821082
1083- // Optimize before creating FTS indices so that compaction
1084- // does not orphan the index data that was just built.
10851083 if total_new_emails > 0 {
10861084 match db_manager. check_optimization_health ( ) . await {
10871085 Ok ( ( needs_optimization, message) ) => {
@@ -1100,10 +1098,18 @@ async fn main() -> Result<()> {
11001098 }
11011099 }
11021100
1103- println ! ( "\n Creating FTS indices for lore table..." ) ;
1104- match db_manager. create_lore_fts_indices ( ) . await {
1105- Ok ( _) => println ! ( "FTS indices created successfully" ) ,
1106- Err ( e) => eprintln ! ( "Warning: Failed to create FTS indices: {}" , e) ,
1101+ // Create FTS indices on first run; merge new rows on
1102+ // subsequent runs. LanceDB's native FTS engine serves
1103+ // unindexed rows via brute-force fallback, so queries
1104+ // remain correct before optimize completes.
1105+ println ! ( "\n Updating FTS indices for lore table..." ) ;
1106+ match db_manager. ensure_lore_fts_indices ( ) . await {
1107+ Ok ( _) => { }
1108+ Err ( e) => eprintln ! ( "Warning: Failed to ensure FTS indices: {}" , e) ,
1109+ }
1110+ match db_manager. optimize_lore_fts_indices ( ) . await {
1111+ Ok ( _) => println ! ( "FTS indices updated successfully" ) ,
1112+ Err ( e) => eprintln ! ( "Warning: Failed to optimize FTS indices: {}" , e) ,
11071113 }
11081114 }
11091115
@@ -1248,8 +1254,6 @@ async fn main() -> Result<()> {
12481254 }
12491255 }
12501256
1251- // Optimize before creating FTS indices so that compaction
1252- // does not orphan the index data that was just built.
12531257 if total_new_emails > 0 {
12541258 match db_manager. check_optimization_health ( ) . await {
12551259 Ok ( ( needs_optimization, message) ) => {
@@ -1268,10 +1272,14 @@ async fn main() -> Result<()> {
12681272 }
12691273 }
12701274
1271- println ! ( "\n Creating FTS indices for lore table..." ) ;
1272- match db_manager. create_lore_fts_indices ( ) . await {
1273- Ok ( _) => println ! ( "FTS indices created successfully" ) ,
1274- Err ( e) => eprintln ! ( "Warning: Failed to create FTS indices: {}" , e) ,
1275+ println ! ( "\n Updating FTS indices for lore table..." ) ;
1276+ match db_manager. ensure_lore_fts_indices ( ) . await {
1277+ Ok ( _) => { }
1278+ Err ( e) => eprintln ! ( "Warning: Failed to ensure FTS indices: {}" , e) ,
1279+ }
1280+ match db_manager. optimize_lore_fts_indices ( ) . await {
1281+ Ok ( _) => println ! ( "FTS indices updated successfully" ) ,
1282+ Err ( e) => eprintln ! ( "Warning: Failed to optimize FTS indices: {}" , e) ,
12751283 }
12761284 }
12771285
0 commit comments