╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ search_thread.zig ────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
68 } else { 69 try srch.remove(DB, index, allocator, before.key, try text(aa, before)); 70 } 71 } else if (new) |after| { 72 try srch.add(DB, index, allocator, after.key, try text(aa, after)); 73 } 74 } 75 76 // the doc keys matching `query_text`, in key order, narrowed to `filter` when 77 // it is keyed the same way 78 pub fn query( 79 comptime DB: type, 80 comptime hash_kind: hash.HashKind, 81 comptime kind: evt.EventKind, 82 haxy_moment: DB.HashMap(.read_only), 83 aa: std.mem.Allocator, 84 query_text: []const u8, 85 filter: ?DB.SortedSet(.read_only), 86 ) !srch.Query(DB) { 87 const cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, indexKey(kind))) orelse return .{ .terms = &.{} }; 88 const index = try DB.SortedMap(.read_only).init(cursor); 89 var results = try srch.Query(DB).init(index, aa, query_text); 90 if (filter) |set| try results.require(aa, set); 91 return results; 92 } 93 94 // the text a thread is indexed under: the title and tags first, so the 95 // tokenizer's caps can only drop the tail of a long description. 96 fn text(aa: std.mem.Allocator, value: Doc) ![]const u8 { 97 return std.mem.concat(aa, u8, &.{ value.title, " ", value.tags, " ", value.description }); 98 } 99