Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(autoindex): title an untitled deck from its logical name, not the blob

Tom Villaniac108d0e5198
diff --git a/engine/crates/xerj-autoindex/src/extract/mod.rs b/engine/crates/xerj-autoindex/src/extract/mod.rs
index 588f51826..4f53642b5 100644
--- a/engine/crates/xerj-autoindex/src/extract/mod.rs
+++ b/engine/crates/xerj-autoindex/src/extract/mod.rs
@@ -209,7 +209,7 @@ pub fn extract(
Family::Eml => eml::extract(path, sn.gzip, sink),
Family::Mbox => mbox::extract(path, sn.gzip, limit_bytes, sink),
Family::Docx => docx::extract(path, sink),
- Family::Pptx => pptx::extract(path, sink),
+ Family::Pptx => pptx::extract(path, sn.logical_name.as_deref().unwrap_or(path), sink),
Family::Sqlite => sqlite_x::extract(path, limit_bytes.map(|_| 500), sink),
Family::SqlDump => sqldump::extract(path, sn.gzip, limit_bytes, sink),
Family::Code => code::extract(path, sn, sink),
diff --git a/engine/crates/xerj-autoindex/src/extract/pptx.rs b/engine/crates/xerj-autoindex/src/extract/pptx.rs
index af6e40627..729943673 100644
--- a/engine/crates/xerj-autoindex/src/extract/pptx.rs
+++ b/engine/crates/xerj-autoindex/src/extract/pptx.rs
@@ -51,8 +51,11 @@ const LIMITS: Limits = Limits {
body: MAX_BODY_BYTES,
};
-pub fn extract(path: &Path, sink: Sink) -> Result<ExtractStats> {
- extract_bounded(path, sink, LIMITS)
+/// `name` is the file as the corpus names it, which under durable preparation
+/// is not `path` (a sealed snapshot blob); a deck with no slide title is
+/// titled from it.
+pub fn extract(path: &Path, name: &Path, sink: Sink) -> Result<ExtractStats> {
+ extract_bounded(path, name, sink, LIMITS)
}
/// Text of one slide (or notes page).
@@ -69,7 +72,7 @@ struct Slide {
body: String,
}
-fn extract_bounded(path: &Path, sink: Sink, limits: Limits) -> Result<ExtractStats> {
+fn extract_bounded(path: &Path, name: &Path, sink: Sink, limits: Limits) -> Result<ExtractStats> {
let mut stats = ExtractStats::default();
let f = std::fs::File::open(path)?;
let mut z = zip::ZipArchive::new(f).context("open pptx container")?;
@@ -125,7 +128,7 @@ fn extract_bounded(path: &Path, sink: Sink, limits: Limits) -> Result<ExtractSta
.iter()
.find_map(|s| s.title.clone())
.unwrap_or_else(|| {
- path.file_stem()
+ name.file_stem()
.map(|s| s.to_string_lossy().to_string())
.unwrap_or_else(|| "untitled".into())
});
@@ -579,6 +582,7 @@ mod tests {
fn run(path: &Path, limits: Limits) -> (Vec<RawRecord>, ExtractStats) {
let mut out = Vec::new();
let stats = extract_bounded(
+ path,
path,
&mut |r| {
out.push(r);
@@ -731,6 +735,30 @@ mod tests {
assert_eq!((stats.records, stats.junk), (0, 1));
}
+ /// Durable preparation extracts a sealed snapshot blob (`00000000`); a deck
+ /// with no slide title must still be titled from its own name (#722's
+ /// class).
+ #[test]
+ fn an_untitled_deck_is_titled_from_the_logical_name_not_the_blob() {
+ let dir = tempfile::tempdir().unwrap();
+ let blob = dir.path().join("00000000");
+ write_deck(
+ &blob,
+ &[slide_xml(&[sp(None, &["body text"])])],
+ &[1],
+ &[None],
+ );
+ let sn = crate::sniff::sniff_with_name(&blob, Path::new("decks/kickoff.pptx")).unwrap();
+ assert_eq!(sn.family, crate::sniff::Family::Pptx);
+ let mut recs = Vec::new();
+ super::super::extract(&blob, &sn, None, &mut |r| {
+ recs.push(r);
+ true
+ })
+ .unwrap();
+ assert_eq!(*field(&recs[0], "title"), "kickoff");
+ }
+
/// A slide longer than one section splits like a PDF page does.
#[test]
fn a_long_slide_is_sectioned() {