nx_docstore_test.nx source
↩ module page · 46 lines · 2123 B
1// nx_docstore_test.nx -- KAT for persistent crawl store.
2// Native sovereign lane; exit 0 = pass, N = assertion N failed.
3// Append 3 docs -> reload -> verify content survived -> rebuild index + search.
4
5import "nx_str.nx"
6import "nx_bm25.nx"
7import "nx_search_inverted.nx" // NxInvIndex + nx_inv_* + nx_bm25_tf (this KAT pins nx_bm25_tf's
8 // contract: present => >0, absent => EXACTLY 0)
9import "nx_docstore.nx"
10
11func main() -> i64 {
12 let path: *u8 = "_offc/nx_docstore_kat.store\x00"
13 nx_docstore_reset(path)
14 nx_docstore_append(path, "http://a/wiki", 13, "diora baird actress wedding crashers", 36)
15 nx_docstore_append(path, "http://a/fan", 12, "diora baird comic con fan photos", 32)
16 nx_docstore_append(path, "http://a/phys", 14, "quantum chromodynamics gluon quark", 34)
17
18 // RELOAD (simulating a fresh process resuming the crawl)
19 let urls: **u8 = sys_mmap(16 * 8) as **u8
20 let ulens: *i64 = sys_mmap(16 * 8) as *i64
21 let texts: **u8 = sys_mmap(16 * 8) as **u8
22 let tlens: *i64 = sys_mmap(16 * 8) as *i64
23 let n: i64 = nx_docstore_load(path, urls, ulens, texts, tlens, 16)
24
25 if n != 3 { return 1 }
26 if ulens[0] != 13 { return 2 }
27 if tlens[2] != 34 { return 3 }
28 // url[0] bytes survived round-trip
29 let exp: *u8 = "http://a/wiki"
30 var i: i64 = 0
31 while i < 13 { if (urls[0][i] as i64) != (exp[i] as i64) { return 4 } i = i + 1 }
32
33 // rebuild the index from the RELOADED corpus and prove search works
34 let idx: *NxInvIndex = nx_inv_new(16)
35 i = 0
36 while i < n { nx_inv_index_row(idx, texts[i], tlens[i], i); i = i + 1 }
37 nx_inv_finalize_offsets(idx)
38 i = 0
39 while i < n { nx_inv_emit_row(idx, texts[i], tlens[i], i); i = i + 1 }
40 // 'comic' is only in the reloaded fan doc; 'gluon' only in phys doc
41 if nx_bm25_tf(texts[1], tlens[1], nx_inv_hash_bytes_lower("comic", 5)) <= 0 { return 5 }
42 if nx_bm25_tf(texts[2], tlens[2], nx_inv_hash_bytes_lower("gluon", 5)) <= 0 { return 6 }
43 if nx_bm25_tf(texts[0], tlens[0], nx_inv_hash_bytes_lower("gluon", 5)) != 0 { return 7 }
44
45 return 0
46}