From 6700f8796a9e86d38ed08d361eb84f0d9868bdec Mon Sep 17 00:00:00 2001 From: Volodymyr Borysenko Date: Mon, 5 Oct 2026 01:50:09 -0700 Subject: [PATCH] fix: keep prepositions and date phrases out of network search criteria --- src/lib/domain/network-search.ts | 17 ++++++++++++++++- tests/network-search.test.ts | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/lib/domain/network-search.ts b/src/lib/domain/network-search.ts index 231ceaa..c836e4e 100644 --- a/src/lib/domain/network-search.ts +++ b/src/lib/domain/network-search.ts @@ -173,8 +173,23 @@ const STOPWORDS = new Set([ "months", "year", "semester", + "in", + "near", + "at", + "on", + "of", + "to", ]); +// "in the last six months" and "in 2024" describe dates, not places. +const NON_PLACE_START = /^(?:last|past|previous|next|recent|recently|this|today|yesterday|\d)/; + +function placeAfterPreposition(value: string) { + const place = value.replace(/^the\b\s*/, ""); + if (!place || place.length > 40 || NON_PLACE_START.test(place)) return null; + return place; +} + const COMMON_GEOS = [ "ukraine", "europe", @@ -333,7 +348,7 @@ export function parseNetworkObjective(input: z.infer new RegExp(`\\b${geo}\\b`).test(text)), - ...extractAfterPhrases(text, ["in", "near"]).filter((value) => value.length <= 40), + ...extractAfterPhrases(text, ["in", "near"]).map(placeAfterPreposition), ]); const institutions = unique([ text.includes("berkeley") ? "Berkeley" : null, diff --git a/tests/network-search.test.ts b/tests/network-search.test.ts index 4dcf548..f4609e3 100644 --- a/tests/network-search.test.ts +++ b/tests/network-search.test.ts @@ -148,6 +148,30 @@ describe("general network search", () => { expect(parsed.topics).not.toContain("Ukraine"); }); + it("does not turn prepositions and date phrases into topics or geographies", () => { + const parsed = parseNetworkObjective({ query: "Find founders I met in the last six months", strictness: "balanced" }, now); + expect(parsed.geographies).toEqual([]); + expect(parsed.topics).not.toContain("in"); + expect(parsed.positiveKeywords).not.toContain("in"); + expect(parsed.dateRange?.preset).toBe("6 months"); + + const year = parseNetworkObjective({ query: "people I emailed in 2024 about climate", strictness: "balanced" }, now); + expect(year.geographies).toEqual([]); + + const place = parseNetworkObjective({ query: "AI founders in the Bay Area", strictness: "balanced" }, now); + expect(place.geographies).toContain("bay area"); + + const results = search("Find founders I met in the last six months", [ + candidate({ + id: "person:other-teams", + entityType: "PERSON", + title: "Founder", + text: "founder building tools for other teams", + }), + ]); + expect(results[0].evidence.some((item) => item.criterion === "Geography")).toBe(false); + }); + it("supports recency and no-follow-up conditions", () => { const results = search("Find founders I met but never followed up with", [ candidate({