code wiki / (root) / nx_dms_search_gate.nx

nx_dms_search_gate.nx source

↩ module page · 71 lines · 3336 B

1// nx_dms_search_gate.nx -- liar-kill gate for consent-gated search. 2// 3// The point: search returns ONLY licensed, active media -- even when an 4// unlicensed asset is a STRONGER textual match -- and revoke/expire drops a 5// result instantly. Ranking is real BM25 (nx_bm25). 6// Returns 0 iff every check holds; a nonzero code pinpoints the first failure. 7 8import "nx_syscalls.nx" 9import "nx_rights_ledger.nx" 10import "nx_dms_catalog.nx" 11import "nx_dms_search.nx" 12 13func main() -> i64 { 14 let l: *NxRightsLedger = nx_rights_ledger_new(16) 15 let c: *NxDmsCatalog = nx_dms_catalog_new(16) 16 let sx: *NxDmsSearchIndex = nx_dms_search_new(16) 17 18 // licenses: 7 -> MERCH + WEB_GALLERY, 9 -> AD (term 1000..11000) 19 if nx_rights_grant(l, 1, 7, NX_USE_MERCH, 1000, 10000) != NX_RL_OK { return 1 } 20 if nx_rights_grant(l, 2, 7, NX_USE_WEB_GALLERY, 1000, 10000) != NX_RL_OK { return 2 } 21 if nx_rights_grant(l, 3, 9, NX_USE_AD_CAMPAIGN, 1000, 10000) != NX_RL_OK { return 3 } 22 23 // catalog: 101/102/103/105 licensed; 104 = UNLICENSED talent 8 24 if nx_dms_catalog_add(c, 101, 7, NX_USE_MERCH, 11, 1500) != NX_DMS_OK { return 4 } 25 if nx_dms_catalog_add(c, 102, 7, NX_USE_WEB_GALLERY, 12, 1500) != NX_DMS_OK { return 5 } 26 if nx_dms_catalog_add(c, 103, 9, NX_USE_AD_CAMPAIGN, 13, 1500) != NX_DMS_OK { return 6 } 27 if nx_dms_catalog_add(c, 104, 8, NX_USE_MERCH, 14, 1500) != NX_DMS_OK { return 7 } 28 if nx_dms_catalog_add(c, 105, 9, NX_USE_AD_CAMPAIGN, 15, 1500) != NX_DMS_OK { return 8 } 29 30 // searchable metadata 31 if nx_dms_search_add(sx, 101, "sunset beach yoga" as *u8) != 0 { return 9 } 32 if nx_dms_search_add(sx, 102, "studio portrait elegant" as *u8) != 0 { return 10 } 33 if nx_dms_search_add(sx, 103, "mountain hiking energy" as *u8) != 0 { return 11 } 34 if nx_dms_search_add(sx, 104, "studio portrait dramatic" as *u8) != 0 { return 12 } 35 if nx_dms_search_add(sx, 105, "forest river calm" as *u8) != 0 { return 13 } 36 37 let ids: *i64 = sys_mmap(16 * 8) as *i64 38 let scs: *i64 = sys_mmap(16 * 8) as *i64 39 40 // 1. "studio portrait" -> ONLY the licensed 102; the unlicensed look-alike 41 // 104 is an equal/stronger textual match but MUST be excluded. 42 var n: i64 = nx_dms_search_query(sx, c, l, "studio portrait" as *u8, 5000, ids, scs, 16) 43 if n != 1 { return 14 } 44 if ids[0] != 102 { return 15 } 45 if scs[0] <= 0 { return 16 } 46 47 // 2. "beach yoga" -> 101 48 n = nx_dms_search_query(sx, c, l, "beach yoga" as *u8, 5000, ids, scs, 16) 49 if n != 1 { return 17 } 50 if ids[0] != 101 { return 18 } 51 52 // 3. no-match query -> 0 results 53 n = nx_dms_search_query(sx, c, l, "zzzzz qqqqq" as *u8, 5000, ids, scs, 16) 54 if n != 0 { return 19 } 55 56 // 4. REVOKE 102's license -> it drops out of search the same instant 57 if nx_rights_revoke(l, 2, 4000) != NX_RL_OK { return 20 } 58 n = nx_dms_search_query(sx, c, l, "studio portrait" as *u8, 5000, ids, scs, 16) 59 if n != 0 { return 21 } 60 61 // 5. 101 is still licensed -> still searchable 62 n = nx_dms_search_query(sx, c, l, "beach yoga" as *u8, 5000, ids, scs, 16) 63 if n != 1 { return 22 } 64 if ids[0] != 101 { return 23 } 65 66 // 6. EXPIRY propagates: past the term, nothing visible -> 0 67 n = nx_dms_search_query(sx, c, l, "beach yoga" as *u8, 99999, ids, scs, 16) 68 if n != 0 { return 24 } 69 70 return 0 71}