code wiki / _hdl_build / nx_docportal_search_serve.nx
nx_docportal_search_serve.nx
buildroot/runtime/_hdl_build/nx_docportal_search_serve.nx
about
nx_docportal_search_serve.nx -- R2: the PUBLIC /search serve handler over the SOVEREIGN seg_store search.
bytes-in -> bytes-out (no socket -- the gate drives it directly, like dad_handle). Parses GET /search?q=<query>,
runs dss_search over the domain's PUBLIC seg_store shard (NO tsv), reads each hit's text (ss_hget) and renders a
branded results page with Content-Length (sites.elf's buffered reverse proxy needs the length). A stale/old-
format shard (-2) degrades to "0 results", never a 500. license_tier: ORIGINAL
dependencies 4 imports · 10 importers
imports: nx_docportal_search_seg.nxnx_artifact_root.nxnx_textcut.nxnx_docprose.nx
imported by: nx_didyoumean_gate.nxnx_docportal_admin_daemon.nxnx_docportal_search_serve_gate.nxnx_estate_search_lib.nxnx_nishi_search_census.nxnx_search_latency_bench.nxnx_search_relevance_bench.nxnx_search_snip_base_20260912.nxnx_serp_census.nxnx_serp_probe.nx
structs
| none |
consts
| 12 | const DSV_ASCII_0: i64 = 48 |
| 13 | const DSV_DEC: i64 = 10 |
| 14 | const DSV_TSBUF: i64 = 16 |
| 16 | const DSV_MAGIC_1000000: i64 = 1000000 |
| 17 | const DSV_MAGIC_1024: i64 = 1024 |
| 18 | const DSV_MAGIC_80000: i64 = 80000 |
| 20 | const DSV_OUTCAP: i64 = 262144 |
| 21 | const DSV_BODYCAP: i64 = 786432 // uniform per-request body mmap size (>= the largest body 600000); munmap'd every request to kill the leak |
| 22 | const DSV_MAXR: i64 = 30 // results per page (20->30 2026-07-24: fuller SERPs; the shrunk tf-scan cap keeps it fast) |
| 23 | const DSV_ENT_FIELD_CAP: i64 = 512 // S11-b: the entity card's jp name and canonical url, copied out of the ranker's table |
| 24 | const DSV_SNIP: i64 = 240 // chars of a hit's text to show |
| 28 | const DSV_TITLE_CAP: i64 = 72 // bytes of the title line shown |
| 29 | const DSV_TITLE_FLOOR: i64 = 56 // degenerate fallback when a document has no titled line at all |
| 30 | const DSV_SENT_MAX: i64 = 320 // hard cap on one "sentence" before dsv_best_sentence gives up looking for . ! ? |
| 31 | const DSV_SNIPSCAN: i64 = 8000 // head window scanned for the best query-covering sentence |
| 32 | const DSV_SENT_MIN: i64 = 40 // shortest span that can qualify as a sentence |
| 33 | const DSV_SENT_MAXNL: i64 = 2 // newlines tolerated inside prose before it reads as a nav blob |
| 244 | const DSV_AGE_MIN: i64 = 60 |
| 245 | const DSV_AGE_HOUR: i64 = 3600 |
| 246 | const DSV_AGE_DAY: i64 = 86400 |
| 277 | const DSV_BOXBYTES: i64 = 64 |
| 464 | const DSV_SCOPE_SITE: i64 = 0 |
| 465 | const DSV_SCOPE_WEB: i64 = 1 |
| 466 | const DSV_SCOPE_TRUSTED: i64 = 2 |
| 467 | const DSV_SCOPE_CONF_CAP: i64 = 4096 |
| 468 | const DSV_PATHCAP: i64 = 1024 |
| 469 | const DSV_CH_LF: i64 = 10 |
| 470 | const DSV_CH_CR: i64 = 13 |
| 471 | const DSV_CH_SP: i64 = 32 |
| 472 | const DSV_CH_HASH: i64 = 35 |
| 543 | const DSV_SCOPE_CORPUS: i64 = 3 |
| 544 | const DSV_SCOPE_WORDCAP: i64 = 32 // a scope word is short; a longer param is no scope (the lookup misses, never truncates a match) |
| 545 | const DSV_SCOPE_PARAM: *u8 = "scope" |
| 546 | const DSV_CH_PIPE: i64 = 124 |
| 547 | const DSV_SURFACE_PUBLIC: *u8 = "public" |
| 1109 | const DSV_HEX_BASE: i64 = 16 |
| 1110 | const DSV_HEX_ALPHA_GAP: i64 = 87 // 'a' minus 10, so the digits 10..15 render as a..f |
| 1111 | const DSV_DIGIT0: i64 = 48 |
| 1112 | const DSV_DIGIT9: i64 = 57 |
functions
| 35 | func dsv_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 36 | func dsv_cat(out: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { out[o] = s[i]; o = o + 1; i = i + 1 } return o } |
| 37 | func dsv_catn(out: *u8, o: i64, v: i64) -> i64 |
| 48 | func dsv_esc(out: *u8, o: i64, src: *u8, n: i64) -> i64 |
| 61 | func dsv_hexval(c: u8) -> i64 called by 1: dsv_urldecode |
| 68 | func dsv_urldecode(src: *u8, n: i64, out: *u8, outcap: i64) -> i64 |
| 91 | func dsv_qparam(req: *u8, req_n: i64, name: *u8, nlen: i64, out: *u8, outcap: i64) -> i64 called by 7: dsv_scopedsv_serp_parsedss_serve_slow_msdsv_doc_servedss_api_searchdss_api_suggest+1 calls 1: dsv_urldecode |
| 129 | func dsv_host(req: *u8, req_n: i64, out: *u8, cap: i64) -> i64 |
| 161 | func dsv_tokq(q: *u8, qn: i64, termstore: *u8, termptrs: *i64, tbl: *u8) -> i64 |
| 185 | func dsv_hl(out: *u8, o: i64, src: *u8, n: i64, termptrs: *i64, nterms: i64, tbl: *u8) -> i64 |
| 221 | func dsv_urlenc(out: *u8, o: i64, src: *u8, n: i64) -> i64 |
| 247 | func dsv_age(body: *u8, b0: i64, secs: i64) -> i64 |
| 257 | func dsv_mkurlkey(cid: i64, out: *u8) -> i64 |
| 279 | func dsv_box() -> *i64 |
| 284 | func dsv_slot(b: *i64, i: i64) -> *i64 { return ((b as i64) + i * 8) as *i64 } |
| 287 | func dsv_snippet_span(txt: *u8, tn: i64, title_end: i64, termptrs: *i64, nterms: i64, tbl: *u8, offout: *i64, lenout: *i64, cutbox: *i64) -> i64 |
| 300 | func dsv_result(body: *u8, b: i64, txt: *u8, tn: i64, cid: i64, q: *u8, qn: i64, termptrs: *i64, nterms: i64, tbl: *u8, url: *u8, ul: i64, webscope: i64) -> i64 |
| 353 | func dsv_style(body: *u8, b: i64) -> i64 |
| 363 | func dsv_u8seq(src: *u8, n: i64, i: i64) -> i64 called by 1: dsv_jesc |
| 382 | func dsv_jesc(out: *u8, o: i64, src: *u8, n: i64) -> i64 |
| 431 | func dsv_respond_json(out: *u8, status: *u8, body: *u8, b: i64) -> i64 |
| 444 | func dsv_respond(out: *u8, status: *u8, body: *u8, b: i64) -> i64 |
| 479 | func dsv_scope_conf_load() -> i64 |
| 493 | func dsv_tok_eq(off: i64, len: i64, lit: *u8) -> i64 |
| 502 | func dsv_default_scope(domain: *u8) -> i64 |
| 554 | func dsv_scopes_conf_set(path: *u8) -> i64 { dsv_scopes_conf_path = path; dsv_scx_loaded = 0; return 0 } |
| 555 | func dsv_scopes_conf_load() -> i64 |
| 577 | func dsv_scx_tok_eq(off: i64, len: i64, lit: *u8) -> i64 |
| 585 | func dsv_word_eq(w: *u8, wn: i64, lit: *u8) -> i64 |
| 593 | func dsv_scope_lookup(w: *u8, wn: i64, domout: *u8, pfxout: *u8, surface_out: *i64) -> i64 |
| 639 | func dsv_scope(req: *u8, req_n: i64, domain: *u8, effdom: *u8) -> i64 |
| 686 | func dsv_scope_link(body: *u8, b: i64, scope: i64) -> i64 |
| 693 | func dsv_scope_name(body: *u8, b: i64, scope: i64) -> i64 |
| 700 | func dsv_tabs(body: *u8, b: i64, q: *u8, qn: i64, scope: i64) -> i64 |
| 718 | func dsv_now_us() -> i64 |
| 730 | func dsv_best_sentence(txt: *u8, tn: i64, termptrs: *i64, nterms: i64, tbl: *u8, offout: *i64, lenout: *i64) -> i64 |
| 816 | func dsv_serp_parse(domain: *u8, req: *u8, req_n: i64, q: *u8, effdom: *u8, box: *i64) -> i64 |
| 831 | func dsv_serp_prelude(body: *u8, q: *u8, qn: i64, webscope: i64) -> i64 |
| 847 | func dsv_serp_rest(effdom: *u8, q: *u8, qn: i64, webscope: i64, page: i64, body: *u8, b0: i64, t0: i64) -> i64 called by 3: dad_serve_earlydss_servemain calls 28: dss_search_offdsv_now_usdss_web_index_segmentsss_tok_tabledsv_tokqdsv_cat+22 |
| 1095 | func dss_serve(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64 called by 7: maindad_handlemainmainmainc_render+1 calls 5: dsv_now_usdsv_serp_parsedsv_serp_preludedsv_serp_restdsv_respond |
| 1113 | func dsv_cathex(out: *u8, o: i64, v: i64) -> i64 |
| 1125 | func dsv_chunk(out: *u8, o0: i64, body: *u8, s: i64, e: i64) -> i64 |
| 1134 | func dsv_chunk_end(out: *u8, o0: i64) -> i64 { return dsv_cat(out, o0, "0\r\n\r\n" as *u8) } |
| 1135 | func dsv_respond_early(out: *u8, body: *u8, b: i64) -> i64 |
| 1143 | func dss_serve_slow_ms(req: *u8, req_n: i64, confpath: *u8) -> i64 |
| 1166 | func dsv_atoin(s: *u8, n: i64, okbox: *i64) -> i64 |
| 1186 | func dsv_doc_serve(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64 called by 3: dad_handlemainmain calls 14: ss_tok_tabledsv_qparamdsv_scopedsv_tokqdsv_atoindss_prefix+8 |
| 1255 | func dss_api_openapi(srv: *u8, out: *u8) -> i64 |
| 1293 | func dss_api_search(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64 |
| 1590 | func dss_api_suggest(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64 |
| 1631 | func dss_api_doc(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64 |