Skip to content

Commit 09b843c

Browse files
author
Your Name
committed
fix(pipeline): rebuild FTS5 index during incremental reindex
The incremental pipeline (pipeline_incremental.c) deletes the old DB and dumps the merged graph via cbm_gbuf_dump_to_sqlite, which bypasses SQLite triggers. The FTS5 table was left empty (0 rows) after every incremental reindex, making search_graph return 0 results for all queries. Fix: after persisting file hashes (the last step before returning), rebuild the FTS5 index with DELETE + INSERT from nodes using cbm_camel_split for camelCase token splitting. Before: full reindex → 672 FTS rows, incremental → 0 FTS rows After: full reindex → 672 FTS rows, incremental → 672 FTS rows
1 parent fc2060b commit 09b843c

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

src/pipeline/pipeline_incremental.c

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,24 @@ int cbm_pipeline_run_incremental(cbm_pipeline_t *p, const char *db_path, cbm_fil
405405
cbm_log_info("incremental.dump", "rc", itoa_buf(dump_rc), "elapsed_ms",
406406
itoa_buf((int)elapsed_ms(t)));
407407

408-
/* Persist file hashes for ALL files */
409-
cbm_store_t *hash_store = cbm_store_open_path(db_path);
410-
if (hash_store) {
411-
persist_hashes(hash_store, project, files, file_count);
412-
cbm_store_close(hash_store);
413-
}
414-
415-
cbm_gbuf_free(existing);
416-
417-
cbm_log_info("incremental.done", "elapsed_ms", itoa_buf((int)elapsed_ms(t0)));
418-
return 0;
419-
}
408+
/* Persist file hashes for ALL files + rebuild FTS5 index */
409+
cbm_store_t *hash_store = cbm_store_open_path(db_path);
410+
if (hash_store) {
411+
persist_hashes(hash_store, project, files, file_count);
412+
413+
/* Rebuild FTS5 index: the btree dump bypasses triggers, and incremental
414+
* merge may add/remove nodes. Rebuild the entire index from scratch.
415+
* cbm_camel_split is registered by cbm_store_open_path automatically. */
416+
cbm_store_exec(hash_store, "DELETE FROM nodes_fts;");
417+
cbm_store_exec(hash_store,
418+
"INSERT INTO nodes_fts(rowid, name, qualified_name, label, file_path) "
419+
"SELECT id, cbm_camel_split(name), qualified_name, label, file_path FROM nodes;");
420+
421+
cbm_store_close(hash_store);
422+
}
423+
424+
cbm_gbuf_free(existing);
425+
426+
cbm_log_info("incremental.done", "elapsed_ms", itoa_buf((int)elapsed_ms(t0)));
427+
return 0;
428+
}

0 commit comments

Comments
 (0)