code wiki / _hdl_build / nx_dss_query.nx

nx_dss_query.nx source

↩ module page · 31 lines · 1831 B

1// nx_dss_query.nx -- CLI over the SOVEREIGN seg_store search: nx_dss_query <domain> <term> 2// Prints ranked cids+scores from the domain's PUBLIC seg_store shard (ss_open->ss_term->ss_hget, no tsv). 3// Verifies the sovereign path on REAL production shards; the query basis for the /search serve handler. ORIGINAL 4import "nx_docportal_search_seg.nx" 5import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 6 7func q_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 8// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 9// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the 10// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls). 11// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign. 12func q_num(v: i64) -> i64 { nxi_out(v); return 0 } 13func q_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 14 15func main(argc: i64, argv: *i64) -> i64 { 16 if argc < 3 { q_puts("usage: nx_dss_query <domain> <term>\n"); return 1 } 17 let domain: *u8 = argv[1] as *u8 18 let query: *u8 = argv[2] as *u8 19 let qn: i64 = q_strlen(query) 20 let cids: *i64 = sys_mmap(64 * 8) as *i64 21 let scores: *i64 = sys_mmap(64 * 8) as *i64 22 let n: i64 = dss_search(domain, query, qn, cids, scores, 20) 23 q_puts("domain="); q_puts(domain); q_puts(" query="); q_puts(query); q_puts(" -> n="); q_num(n); q_puts("\n") 24 if n == (0 - 2) { q_puts(" (-2: a live segment lacks .terms -- old-format shard, compaction is the upgrade)\n"); return 2 } 25 var i: i64 = 0 26 while i < n { 27 q_puts(" cid="); q_num(cids[i]); q_puts(" score="); q_num(scores[i]); q_puts("\n") 28 i = i + 1 29 } 30 return 0 31}