code wiki / _hdl_build / nx_docportal_search_serve.nx

nx_docportal_search_serve.nx

buildroot/runtime/_hdl_build/nx_docportal_search_serve.nx

95739 B1679 linesdepth 5pulls 13 transitivereach 16 importersview sourcekind librarytopic docportal
docsdependenciesstructsconstsfunctions

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

nx_docportal_search_seg.nx nx_artifact_root.nx nx_textcut.nx nx_docprose.nx nx_docportal_search_serve.nx nx_didyoumean_gate.nx nx_docportal_admin_daemon.nx nx_docportal_search_serve_gate.nx nx_estate_search_lib.nx nx_nishi_search_census.nx nx_search_latency_bench.nx nx_search_relevance_bench.nx nx_search_snip_base_20260912.nx nx_serp_census.nx nx_serp_probe.nx

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

12const DSV_ASCII_0: i64 = 48
13const DSV_DEC: i64 = 10
14const DSV_TSBUF: i64 = 16
16const DSV_MAGIC_1000000: i64 = 1000000
17const DSV_MAGIC_1024: i64 = 1024
18const DSV_MAGIC_80000: i64 = 80000
20const DSV_OUTCAP: i64 = 262144
21const DSV_BODYCAP: i64 = 786432 // uniform per-request body mmap size (>= the largest body 600000); munmap'd every request to kill the leak
22const DSV_MAXR: i64 = 30 // results per page (20->30 2026-07-24: fuller SERPs; the shrunk tf-scan cap keeps it fast)
23const DSV_ENT_FIELD_CAP: i64 = 512 // S11-b: the entity card's jp name and canonical url, copied out of the ranker's table
24const DSV_SNIP: i64 = 240 // chars of a hit's text to show
28const DSV_TITLE_CAP: i64 = 72 // bytes of the title line shown
29const DSV_TITLE_FLOOR: i64 = 56 // degenerate fallback when a document has no titled line at all
30const DSV_SENT_MAX: i64 = 320 // hard cap on one "sentence" before dsv_best_sentence gives up looking for . ! ?
31const DSV_SNIPSCAN: i64 = 8000 // head window scanned for the best query-covering sentence
32const DSV_SENT_MIN: i64 = 40 // shortest span that can qualify as a sentence
33const DSV_SENT_MAXNL: i64 = 2 // newlines tolerated inside prose before it reads as a nav blob
244const DSV_AGE_MIN: i64 = 60
245const DSV_AGE_HOUR: i64 = 3600
246const DSV_AGE_DAY: i64 = 86400
277const DSV_BOXBYTES: i64 = 64
464const DSV_SCOPE_SITE: i64 = 0
465const DSV_SCOPE_WEB: i64 = 1
466const DSV_SCOPE_TRUSTED: i64 = 2
467const DSV_SCOPE_CONF_CAP: i64 = 4096
468const DSV_PATHCAP: i64 = 1024
469const DSV_CH_LF: i64 = 10
470const DSV_CH_CR: i64 = 13
471const DSV_CH_SP: i64 = 32
472const DSV_CH_HASH: i64 = 35
543const DSV_SCOPE_CORPUS: i64 = 3
544const DSV_SCOPE_WORDCAP: i64 = 32 // a scope word is short; a longer param is no scope (the lookup misses, never truncates a match)
545const DSV_SCOPE_PARAM: *u8 = "scope"
546const DSV_CH_PIPE: i64 = 124
547const DSV_SURFACE_PUBLIC: *u8 = "public"
1109const DSV_HEX_BASE: i64 = 16
1110const DSV_HEX_ALPHA_GAP: i64 = 87 // 'a' minus 10, so the digits 10..15 render as a..f
1111const DSV_DIGIT0: i64 = 48
1112const DSV_DIGIT9: i64 = 57

functions

35func dsv_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
36func 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 }
37func dsv_catn(out: *u8, o: i64, v: i64) -> i64
48func dsv_esc(out: *u8, o: i64, src: *u8, n: i64) -> i64
61func dsv_hexval(c: u8) -> i64
called by 1: dsv_urldecode
68func dsv_urldecode(src: *u8, n: i64, out: *u8, outcap: i64) -> i64
called by 1: dsv_qparam calls 1: dsv_hexval
91func dsv_qparam(req: *u8, req_n: i64, name: *u8, nlen: i64, out: *u8, outcap: i64) -> i64
129func dsv_host(req: *u8, req_n: i64, out: *u8, cap: i64) -> i64
161func dsv_tokq(q: *u8, qn: i64, termstore: *u8, termptrs: *i64, tbl: *u8) -> i64
185func dsv_hl(out: *u8, o: i64, src: *u8, n: i64, termptrs: *i64, nterms: i64, tbl: *u8) -> i64
221func dsv_urlenc(out: *u8, o: i64, src: *u8, n: i64) -> i64
247func dsv_age(body: *u8, b0: i64, secs: i64) -> i64
called by 1: dsv_serp_rest calls 2: dsv_catndsv_cat
257func dsv_mkurlkey(cid: i64, out: *u8) -> i64
279func dsv_box() -> *i64
284func dsv_slot(b: *i64, i: i64) -> *i64 { return ((b as i64) + i * 8) as *i64 }
287func dsv_snippet_span(txt: *u8, tn: i64, title_end: i64, termptrs: *i64, nterms: i64, tbl: *u8, offout: *i64, lenout: *i64, cutbox: *i64) -> i64
300func 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
353func dsv_style(body: *u8, b: i64) -> i64
363func dsv_u8seq(src: *u8, n: i64, i: i64) -> i64
called by 1: dsv_jesc
382func dsv_jesc(out: *u8, o: i64, src: *u8, n: i64) -> i64
431func dsv_respond_json(out: *u8, status: *u8, body: *u8, b: i64) -> i64
444func dsv_respond(out: *u8, status: *u8, body: *u8, b: i64) -> i64
479func dsv_scope_conf_load() -> i64
called by 1: dsv_default_scope calls 2: ar_resolvear_read
493func dsv_tok_eq(off: i64, len: i64, lit: *u8) -> i64
called by 1: dsv_default_scope calls 1: dsv_slen
502func dsv_default_scope(domain: *u8) -> i64
554func dsv_scopes_conf_set(path: *u8) -> i64 { dsv_scopes_conf_path = path; dsv_scx_loaded = 0; return 0 }
555func dsv_scopes_conf_load() -> i64
577func dsv_scx_tok_eq(off: i64, len: i64, lit: *u8) -> i64
called by 1: dsv_scope_lookup calls 1: dsv_slen
585func dsv_word_eq(w: *u8, wn: i64, lit: *u8) -> i64
called by 1: dsv_scope calls 1: dsv_slen
593func dsv_scope_lookup(w: *u8, wn: i64, domout: *u8, pfxout: *u8, surface_out: *i64) -> i64
639func dsv_scope(req: *u8, req_n: i64, domain: *u8, effdom: *u8) -> i64
693func dsv_scope_name(body: *u8, b: i64, scope: i64) -> i64
700func dsv_tabs(body: *u8, b: i64, q: *u8, qn: i64, scope: i64) -> i64
called by 1: dsv_serp_prelude calls 2: dsv_catdsv_urlenc
718func dsv_now_us() -> i64
730func dsv_best_sentence(txt: *u8, tn: i64, termptrs: *i64, nterms: i64, tbl: *u8, offout: *i64, lenout: *i64) -> i64
816func dsv_serp_parse(domain: *u8, req: *u8, req_n: i64, q: *u8, effdom: *u8, box: *i64) -> i64
831func dsv_serp_prelude(body: *u8, q: *u8, qn: i64, webscope: i64) -> i64
847func dsv_serp_rest(effdom: *u8, q: *u8, qn: i64, webscope: i64, page: i64, body: *u8, b0: i64, t0: i64) -> i64
1095func dss_serve(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64
1113func dsv_cathex(out: *u8, o: i64, v: i64) -> i64
called by 2: dsv_chunkmain
1125func dsv_chunk(out: *u8, o0: i64, body: *u8, s: i64, e: i64) -> i64
1134func dsv_chunk_end(out: *u8, o0: i64) -> i64 { return dsv_cat(out, o0, "0\r\n\r\n" as *u8) }
called by 2: dad_serve_earlymain calls 1: dsv_cat
1135func dsv_respond_early(out: *u8, body: *u8, b: i64) -> i64
1143func dss_serve_slow_ms(req: *u8, req_n: i64, confpath: *u8) -> i64
1166func dsv_atoin(s: *u8, n: i64, okbox: *i64) -> i64
1186func dsv_doc_serve(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64
1255func dss_api_openapi(srv: *u8, out: *u8) -> i64
1590func dss_api_suggest(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64
1631func dss_api_doc(domain: *u8, req: *u8, req_n: i64, out: *u8) -> i64