use std::fs; use std::time::Instant; use frxd::index::{Collection, LocalIndex, response_items}; use frxd::message::{EXPOSURE_FULL, build_response}; #[test] fn thousand_file_corpus_is_searchable_and_honest() { let temp = tempfile::tempdir().unwrap(); let docs = temp.path().join("corpus"); fs::create_dir_all(&docs).unwrap(); let total = 1000; for i in 0..total { let part = docs.join(format!("part{:02}", i / 100)); fs::create_dir_all(&part).unwrap(); fs::write( part.join(format!("doc{i:04}.txt")), format!("commonneedle unique{i} rust document number {i}"), ) .unwrap(); } let index = LocalIndex::open(&temp.path().join("index")).unwrap(); let start = Instant::now(); let added = index .add_collection(&Collection { name: "corpus".to_string(), path: docs.display().to_string(), shared: true, exposure: EXPOSURE_FULL.to_string(), }) .unwrap(); println!("indexed {added} documents in {:?}", start.elapsed()); assert_eq!(added, total); assert_eq!(index.doc_count(), total as u64); let start = Instant::now(); let (hits, matches) = index.search("commonneedle", 10, true).unwrap(); println!("query matched {matches} documents in {:?}", start.elapsed()); assert_eq!(matches, total as u64); assert_eq!(hits.len(), 10); let response = build_response("scale", response_items(&hits), matches, 10); assert!(response.truncated); assert_eq!(response.more_available, (total - 10) as u64); assert!(serde_json::to_string(&response).unwrap().len() > 0); let (hits, matches) = index.search("unique777", 10, true).unwrap(); assert_eq!(matches, 1); assert!(hits[0].summary.contains("unique777")); }