Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion site/lib/lib.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 13 additions & 3 deletions site/lib/search.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down