code wiki / _hdl_build / nx_onsite_index.nx
nx_onsite_index.nx
buildroot/runtime/_hdl_build/nx_onsite_index.nx
about
nx_onsite_index.nx -- SITE-AGNOSTIC INGESTOR for the reusable onsite search client. Turns a site's
search source (a 2-column "id<TAB>text" TSV -- the universal "search manifest source") into the durable
pair the client reads: an inverted index (nx_search_inverted) + a MANIFEST (url<TAB>title<TAB>text, one
line per doc, docid = line). REUSE not reinvent -- the gallery ALREADY produces id<TAB>text
(knowledge/status/galx_search.tsv via nx_galx_search_index); any site emits the same shape and gets BM25
onsite search for free. "find files and articles": id = the file/article id, url = <url_prefix><id>, text
= its searchable body.
Usage: nx_onsite_index <src_id_text.tsv> <url_prefix> <idx_out> <manifest_out> [max_docs]
e.g. nx_onsite_index knowledge/status/galx_search.tsv /img/ knowledge/index/gallery.idx knowledge/index/gallery.manifest
COLLECT-THEN-BUILD with DEDUP: one pass collects the UNIQUE-by-id rows (galx_search.tsv had ~38% duplicate
cids -- re-indexed images -- which would otherwise surface the same image many times); then a clean 2-pass
index build + manifest write over the deduped set keeps idx docids and manifest lines aligned by construction.
Pure-numeric tokens (image seeds/dims/steps) are scrubbed from the INDEXED copy (search noise); the manifest
keeps the original text. license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_search_inverted_persist.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 19 | const OI_DEFAULT_MAX: i64 = 4000000 |
| 20 | const OI_SCRATCH_CAP: i64 = 1048576 // per-doc scrub scratch (>= longest doc text) |
| 21 | const OI_VOCAB_CAP: i64 = 1048576 // 2^20 vocab slots (power of 2): CEILING for large corpora w/o saturating |
| 22 | const OI_VOCAB_MIN: i64 = 2048 // 2^11 floor: smallest vocab table (tiny corpora still get headroom) |
| 23 | const OI_DEDUP_CAP: i64 = 2097152 // 2^21 id-dedup hash-set slots (power of 2) |
functions
| 25 | func oi_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } called by 1: main |
| 26 | func oi_num(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=(48 as u8);k=1}; while m>0{t[k]=((48+(m%10)) as u8);m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(1,bb,k); return 0 } called by 1: main |
| 27 | func oi_strlen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } called by 1: main |
| 28 | func oi_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ if s[i]>=(48 as u8){ if s[i]<=(57 as u8){ v=v*10+((s[i]-(48 as u8)) as i64) } } i=i+1 } return v } called by 1: main |
| 31 | func oi_next_pow2(n: i64) -> i64 { var p: i64=1; while p<n { p=p*2 } return p } called by 1: oi_autosize_vocab |
| 37 | func oi_autosize_vocab(total_txt_bytes: i64) -> i64 |
| 46 | func oi_scrub_numeric(src: *u8, n: i64, dst: *u8) -> i64 |
| 74 | func oi_dedup_seen(set: *i64, cap: i64, h: i64) -> i64 called by 1: main |
| 89 | func main(argc: i64, argv: *i64) -> i64 |