diff --git a/site/lib/lib.test.mjs b/site/lib/lib.test.mjs index a43455b4..aa1c06fc 100644 --- a/site/lib/lib.test.mjs +++ b/site/lib/lib.test.mjs @@ -2739,8 +2739,16 @@ await section("needs-review open question (#211)", async () => { eq("delivery filter: a desktop app fails Web app", pf({ status: "active", delivery: ["desktop-app"] }, { ...FD, delivery: "web" }), false); eq("delivery filter: no delivery fails a chosen group", pf({ status: "active", formats: ["PNG"] }, { ...FD, delivery: "godot" }), false); // Every merged tag spelling still finds an entry tagged with the kept one (#96). - const tagAliases = JSON.parse(fsTest.readFileSync(new URL("../value-aliases.json", import.meta.url), "utf8")).tags; + const tagAliases = JSON.parse(fsTest.readFileSync(new URL("../value-aliases.json", import.meta.url), "utf8")).tags; const { searchFields: sf, scoreFields: sc, queryTests: qt } = await import("./search.mjs"); + + // Plural handling must not truncate words ending in "ss" (#337). + eq("search: bass does not match base", sc(["base", "", "", ""], qt("bass")), 0); + eq("search: bass does not match basic", sc(["basic", "", "", ""], qt("bass")), 0); + eq("search: moss does not match most", sc(["most", "", "", ""], qt("moss")), 0); + eq("search: bass matches bass", sc(["bass", "", "", ""], qt("bass")) > 0, true); + eq("search: buttons matches button", sc(["button", "", "", ""], qt("buttons")) > 0, true); + for (const [old, kept] of Object.entries(tagAliases)) { const entry = { id: "x", name: "Pack", tags: [kept], subcategories: [], formats: [], license: "CC0", category: "2d" }; eq(`merged tag: "${old}" finds an entry tagged "${kept}"`, sc(sf(entry), qt(old)) > 0, true); diff --git a/site/lib/search.mjs b/site/lib/search.mjs index 317d1a5a..ea97c500 100644 --- a/site/lib/search.mjs +++ b/site/lib/search.mjs @@ -102,9 +102,19 @@ export const QUERY_FOLDS = [ */ export function wordTest(word) { const forms = [word]; - if (word.length > 3 && word.endsWith("s")) forms.push(word.slice(0, -1)); - for (const f of [...forms]) forms.push(...(SYNONYMS[f] || [])); - const alt = forms.map((f) => f.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|"); + + if (word.length > 3 && word.endsWith("s") && !word.endsWith("ss")) { + forms.push(word.slice(0, -1)); + } + + for (const f of [...forms]) { + forms.push(...(SYNONYMS[f] || [])); + } + + const alt = forms + .map((f) => f.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) + .join("|"); + return new RegExp(`(?:^|[^\\p{L}\\p{N}])(?:${alt})`, "u"); }