╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ search_thread.zig ────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
31 old_maybe: anytype, 32 new: anytype, 33 ) !void { 34 var arena = std.heap.ArenaAllocator.init(allocator); 35 defer arena.deinit(); 36 const aa = arena.allocator(); 37 const old_text = if (old_maybe) |old| try text(aa, old) else ""; 38 const new_text = try text(aa, new); 39 if (std.mem.eql(u8, old_text, new_text)) return; 40 const index = try DB.SortedMap(.read_write).init(try haxy_moment.putCursor(hash.hashInt(hash_kind, indexKey(kind)))); 41 try srch.replace(DB, index, allocator, key, old_text, new_text); 42 } 43 44 // the doc keys matching `query_text`, in key order, narrowed to `filter` when 45 // it is keyed the same way 46 pub fn query( 47 comptime DB: type, 48 comptime hash_kind: hash.HashKind, 49 comptime kind: evt.EventKind, 50 haxy_moment: DB.HashMap(.read_only), 51 aa: std.mem.Allocator, 52 query_text: []const u8, 53 filter: ?DB.SortedSet(.read_only), 54 ) !srch.Query(DB) { 55 const cursor = try haxy_moment.getCursor(hash.hashInt(hash_kind, indexKey(kind))) orelse return .{ .terms = .empty }; 56 const index = try DB.SortedMap(.read_only).init(cursor); 57 var results = try srch.Query(DB).init(index, aa, query_text); 58 if (filter) |set| try results.require(aa, set); 59 return results; 60 } 61 62 // the text a thread is indexed under, none once it is removed: the title and 63 // labels first, so the tokenizer's caps can only drop the tail of a long 64 // description. 65 fn text(aa: std.mem.Allocator, record: anytype) ![]const u8 { 66 if (record.removed) return ""; 67 return std.mem.concat(aa, u8, &.{ record.event.title, " ", record.event.labels, " ", record.event.description }); 68 } 69