Store embed titles and search them

This commit is contained in:
Fisto
2026-09-17 13:10:16 +02:00
parent c6caa168be
commit 557ba5ca7e
13 changed files with 200 additions and 10 deletions
+56
View File
@@ -29,6 +29,7 @@ import { isoFromSnowflake, snowflakeFromIso } from "../src/snowflake.js";
import {
dirSizeBytes,
listScrapes,
normalizeTitleKey,
readScrapeMeta,
ScrapeStore,
writeScrapeMeta
@@ -1347,6 +1348,61 @@ void (async () => {
store.close();
});
await test("title search matches word prefixes and exact phrases", () => {
const dir = join(root, "title-search");
mkdirSync(dir, { recursive: true });
const store = new ScrapeStore(dir);
const embed = (url: string, title: string) => ({
type: "video",
url,
title,
provider: "YouTube",
videoUrl: url,
imageUrl: null,
thumbnailUrl: null
});
store.insertPage([
message("1000", {
attachments: [attachment({ filename: "no-title.png", contentType: "image/png" })],
embeds: [
embed("https://www.youtube.com/watch?v=a", "Man who jumps over car"),
embed("https://www.youtube.com/watch?v=b", "Human cannonball"),
embed("https://www.youtube.com/watch?v=c", "Woman's Day: 3 Things!")
]
})
]);
const ids = (options: Record<string, unknown>) =>
store
.queryMedia({ limit: 50, ...options })
.map(row => row.url.split("v=")[1])
.sort();
// Prefix tokens in any order, but only at word starts.
assert.deepEqual(ids({ titleQuery: "Ma Ca Ju" }), ["a"]);
assert.deepEqual(ids({ titleQuery: "man" }), ["a"]);
assert.deepEqual(ids({ titleQuery: "man car" }), ["a"]);
assert.deepEqual(ids({ titleQuery: "cannon" }), ["b"]);
assert.deepEqual(ids({ titleQuery: "hum" }), ["b"]);
assert.deepEqual(ids({ titleQuery: "an" }), []);
// Exact mode is one phrase.
assert.deepEqual(ids({ titleQuery: "man who jumps", titleExact: true }), ["a"]);
assert.deepEqual(ids({ titleQuery: "man car", titleExact: true }), []);
// Punctuation folds away.
assert.deepEqual(ids({ titleQuery: "woman's day" }), ["c"]);
assert.deepEqual(ids({ titleQuery: "3 things" }), ["c"]);
store.close();
});
await test("normalizeTitleKey collapses punctuation and case", () => {
assert.equal(normalizeTitleKey("Woman's Day: 3 Things!"), "woman s day 3 things");
assert.equal(normalizeTitleKey(" A---B "), "a b");
});
await test("provider filters are the curated archive list", () => {
assert.ok(PROVIDER_FILTERS.length >= 12, `provider list has ${PROVIDER_FILTERS.length} entries`);
assert.equal(new Set(PROVIDER_FILTERS).size, PROVIDER_FILTERS.length);