use tracing::info;
use crate::document::DocumentTree;
use crate::index::config::PipelineOptions;
use crate::index::parse::DocumentFormat;
use crate::storage::PersistedDocument;
use crate::utils::fingerprint::Fingerprint;
pub enum IndexAction {
Skip(SkipInfo),
FullIndex {
existing_id: Option<String>,
},
IncrementalUpdate {
old_tree: DocumentTree,
existing_id: String,
},
}
pub struct SkipInfo {
pub doc_id: String,
pub name: String,
pub format: DocumentFormat,
pub description: Option<String>,
pub page_count: Option<usize>,
}
pub fn resolve_action(
file_bytes: &[u8],
stored_doc: &PersistedDocument,
pipeline_options: &PipelineOptions,
format: DocumentFormat,
) -> IndexAction {
let current_fp = Fingerprint::from_bytes(file_bytes);
if !stored_doc
.meta
.needs_reprocessing(¤t_fp, pipeline_options.processing_version)
{
info!("File fingerprint unchanged, skipping");
return IndexAction::Skip(SkipInfo {
doc_id: stored_doc.meta.id.clone(),
name: stored_doc.meta.name.clone(),
format,
description: stored_doc.meta.description.clone(),
page_count: stored_doc.meta.page_count,
});
}
let current_logic_fp = pipeline_options.logic_fingerprint();
if stored_doc.meta.logic_fingerprint != current_logic_fp
&& !stored_doc.meta.logic_fingerprint.is_zero()
{
info!("Logic fingerprint changed, full reprocess required");
return IndexAction::FullIndex {
existing_id: Some(stored_doc.meta.id.clone()),
};
}
info!("Content changed, pipeline unchanged → incremental update");
IndexAction::IncrementalUpdate {
old_tree: stored_doc.tree.clone(),
existing_id: stored_doc.meta.id.clone(),
}
}