╭ changed ────────────╮ │src/search_thread.zig│ ╰─────────────────────╯ ╭───────────╮ │← all files│ ╰───────────╯ ╭──────────────────────────────────────────────────────────────────────────────────╮ │38 }; │ │39 } │ │40 │ │41 -// replace `old`'s postings with `new`'s. an unchanged doc costs nothing: a │ │42 -// status change or an edit that leaves the indexed fields alone returns here.│ │41 +// move `old`'s postings to `new`'s. an unchanged doc costs nothing: a status │ │42 +// change or an edit that leaves the indexed fields alone returns here. both │ │43 +// sides share a doc key, since a thread keeps the one it was created with. │ │44 pub fn update( │ │45 comptime DB: type, │ │46 comptime hash_kind: hash.HashKind, │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮ │60 │ │61 var arena = std.heap.ArenaAllocator.init(allocator); │ │62 defer arena.deinit(); │ │63 + const aa = arena.allocator(); │ │64 const index = try DB.SortedMap(.read_write).init(try haxy_moment.putCursor(hash.hashInt(hash_kind, indexKey(kind))));│ │63 - if (old) |before| try srch.remove(DB, index, allocator, before.key, try text(arena.allocator(), before)); │ │64 - if (new) |after| try srch.add(DB, index, allocator, after.key, try text(arena.allocator(), after)); │ │65 + if (old) |before| { │ │66 + if (new) |after| { │ │67 + try srch.replace(DB, index, allocator, after.key, try text(aa, before), try text(aa, after)); │ │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 │ ╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯