use tracing::error;
use crate::data::executor::core_loop::CoreLoop;
use crate::data::executor::fts_text::extract_fts_text;
use super::document::UndoDocumentContext;
impl CoreLoop {
pub(super) fn reindex_restored_document_fts(
&self,
ctx: UndoDocumentContext<'_>,
surrogate: nodedb_types::Surrogate,
old_value: &[u8],
) -> Result<(), (usize, String)> {
let UndoDocumentContext {
database_id,
tid,
entry_index,
collection,
document_id,
} = ctx;
let config_key = (
crate::types::DatabaseId::new(database_id),
crate::types::TenantId::new(tid),
collection.to_string(),
);
let Some(config) = self.doc_configs.get(&config_key) else {
return Ok(());
};
let Some(doc) = self.decode_stored_document(config, old_value) else {
return Ok(());
};
let text = extract_fts_text(&doc);
if text.is_empty() {
return Ok(());
}
self.inverted
.index_document(
database_id,
crate::types::TenantId::new(tid),
collection,
surrogate,
&text,
)
.map_err(|e| {
error!(
core = self.core_id,
entry_index,
collection = %collection,
document_id = %document_id,
error = %e,
"transaction undo: FTS re-index failed; shard state unknown"
);
(
entry_index,
format!("fts re-index on {collection}/{document_id}: {e}"),
)
})
}
}