nx_dms_search_store_gate.nx source
↩ module page · 48 lines · 2422 B
1// nx_dms_search_store_gate.nx -- durability gate for the search index.
2// Build index (3 docs) -> baseline query -> save -> reload into a FRESH index
3// -> count survived AND queries on the reloaded index return the same results
4// (text bytes survived the round-trip, tokenization + BM25 still work).
5
6import "nx_syscalls.nx"
7import "nx_rights_ledger.nx"
8import "nx_dms_catalog.nx"
9import "nx_dms_search.nx"
10import "nx_dms_search_store.nx"
11
12func main() -> i64 {
13 let rl: *NxRightsLedger = nx_rights_ledger_new(16)
14 let cat: *NxDmsCatalog = nx_dms_catalog_new(16)
15 let sx: *NxDmsSearchIndex = nx_dms_search_new(16)
16 // all three assets licensed (7/MERCH) so they're searchable candidates
17 if nx_rights_grant(rl, 1, 7, NX_USE_MERCH, 1000, 100000) != NX_RL_OK { return 1 }
18 if nx_dms_catalog_add(cat, 101, 7, NX_USE_MERCH, 11, 1500) != NX_DMS_OK { return 2 }
19 if nx_dms_catalog_add(cat, 102, 7, NX_USE_MERCH, 12, 1500) != NX_DMS_OK { return 3 }
20 if nx_dms_catalog_add(cat, 103, 7, NX_USE_MERCH, 13, 1500) != NX_DMS_OK { return 4 }
21 if nx_dms_search_add(sx, 101, "sunset beach yoga" as *u8) != 0 { return 5 }
22 if nx_dms_search_add(sx, 102, "studio portrait elegant" as *u8) != 0 { return 6 }
23 if nx_dms_search_add(sx, 103, "mountain hiking trail" as *u8) != 0 { return 7 }
24
25 let ids: *i64 = sys_mmap(16 * 8) as *i64
26 let scs: *i64 = sys_mmap(16 * 8) as *i64
27
28 // baseline query before save
29 if nx_dms_search_query(sx, cat, rl, "beach" as *u8, 5000, ids, scs, 16) != 1 { return 8 }
30 if ids[0] != 101 { return 9 }
31
32 // SAVE then reload into a brand-new index
33 if nx_dms_search_save(sx, "/tmp/nx_search-" as *u8, 1) != 0 { return 10 }
34 let sx2: *NxDmsSearchIndex = nx_dms_search_load("/tmp/nx_search-" as *u8)
35 if nx_dms_search_count(sx2) != 3 { return 11 }
36
37 // queries on the RELOADED index (text bytes survived the round-trip)
38 if nx_dms_search_query(sx2, cat, rl, "beach" as *u8, 5000, ids, scs, 16) != 1 { return 12 }
39 if ids[0] != 101 { return 13 }
40 if nx_dms_search_query(sx2, cat, rl, "studio" as *u8, 5000, ids, scs, 16) != 1 { return 14 }
41 if ids[0] != 102 { return 15 }
42 if nx_dms_search_query(sx2, cat, rl, "mountain" as *u8, 5000, ids, scs, 16) != 1 { return 16 }
43 if ids[0] != 103 { return 17 }
44 // non-match still 0
45 if nx_dms_search_query(sx2, cat, rl, "zzzzz" as *u8, 5000, ids, scs, 16) != 0 { return 18 }
46
47 return 0
48}