quick_search/crates/quicksearch-core/examples/oleprobe.rs
= e8057e596c
All checks were successful
CI / linux (push) Successful in 3m2s
CI / windows-cross (push) Successful in 2m7s
CI / release (push) Successful in 13s
Improved Windows handling of Cloud folders. Improved indexing status reporting. Cleaned up some comments. Added support for old M$ word documents. Improved idle memory consumption.
2026-08-05 18:05:04 -04:00

40 lines
1.4 KiB
Rust

//! Print what the legacy-Office extractor gets out of a real file.
//!
//! The unit tests build their own fixtures, which proves the parsers agree
//! with the format specs as read. This runs them against files a real
//! producer wrote, which is the other half of the question.
//!
//! cargo run --example oleprobe -- some.doc some.xls some.ppt
use std::path::Path;
use quicksearch_core::extract::{Extractor, Registry};
fn main() {
let mut failures = 0;
for arg in std::env::args().skip(1) {
let path = Path::new(&arg);
println!("=== {} ===", path.display());
match quicksearch_core::extract::office::OfficeExtractor.extract(path) {
Ok(content) => {
let text = content.text;
println!("{} chars", text.chars().count());
let preview: String = text.chars().take(400).collect();
println!("{}", preview);
}
Err(e) => {
failures += 1;
println!("FAILED: {}", e);
}
}
// The dispatch a real index would take: MIME, not extension.
let registry = Registry::default_set();
let mime = mime_guess::from_path(path)
.first()
.map(|m| m.essence_str().to_string())
.unwrap_or_default();
println!("(mime {} claimed: {})", mime, registry.supports(&mime));
println!();
}
std::process::exit(if failures > 0 { 1 } else { 0 });
}