mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Don't show completely unrelated chapter suggestions
Chapter suggestions should be at least slightly related to what the user has already typed. This change stops the server from sending suggestions that postgresql deems to be "less than 10% similar" Also modified tests to reflect this change.
This commit is contained in:
parent
d75b9ddcaa
commit
3f026409cd
2 changed files with 13 additions and 9 deletions
|
@ -27,10 +27,11 @@ export async function getChapterNames(req: Request, res: Response): Promise<Resp
|
||||||
FROM "videoInfo"
|
FROM "videoInfo"
|
||||||
WHERE "channelID" = ?
|
WHERE "channelID" = ?
|
||||||
) AND "description" != ''
|
) AND "description" != ''
|
||||||
|
AND similarity("description", ?) >= 0.1
|
||||||
GROUP BY "description"
|
GROUP BY "description"
|
||||||
ORDER BY SUM("votes"), similarity("description", ?) DESC
|
ORDER BY SUM("votes"), similarity("description", ?) DESC
|
||||||
LIMIT 5;`
|
LIMIT 5;`
|
||||||
, [channelID, description]) as { description: string }[];
|
, [channelID, description, description]) as { description: string }[];
|
||||||
|
|
||||||
if (descriptions?.length > 0) {
|
if (descriptions?.length > 0) {
|
||||||
return res.status(200).json(descriptions.map(d => ({
|
return res.status(200).json(descriptions.map(d => ({
|
||||||
|
|
|
@ -16,17 +16,18 @@ describe("getChapterNames", function () {
|
||||||
"Weird name",
|
"Weird name",
|
||||||
"A different one",
|
"A different one",
|
||||||
"Something else",
|
"Something else",
|
||||||
|
"Weirder name",
|
||||||
];
|
];
|
||||||
|
|
||||||
const nameSearch = (query: string, expected: string): Promise<void> => {
|
const nameSearch = (query: string, expected: string | null, expectedResults: number): Promise<void> => {
|
||||||
const expectedData = [{
|
const expectedData = [{
|
||||||
description: expected
|
description: expected
|
||||||
}];
|
}];
|
||||||
return client.get(`${endpoint}?description=${query}&channelID=${chapterChannelID}`)
|
return client.get(`${endpoint}?description=${query}&channelID=${chapterChannelID}`)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
assert.strictEqual(res.status, 200);
|
assert.strictEqual(res.status, expectedResults == 0 ? 404 : 200);
|
||||||
assert.strictEqual(res.data.length, chapterNames.length);
|
assert.strictEqual(res.data.length, expectedResults);
|
||||||
assert.ok(partialDeepEquals(res.data, expectedData));
|
if (expected != null) assert.ok(partialDeepEquals(res.data, expectedData));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,11 +36,13 @@ describe("getChapterNames", function () {
|
||||||
await insertChapter(db, chapterNames[0], { videoID: chapterNamesVid1, startTime: 60, endTime: 80 });
|
await insertChapter(db, chapterNames[0], { videoID: chapterNamesVid1, startTime: 60, endTime: 80 });
|
||||||
await insertChapter(db, chapterNames[1], { videoID: chapterNamesVid1, startTime: 70, endTime: 75 });
|
await insertChapter(db, chapterNames[1], { videoID: chapterNamesVid1, startTime: 70, endTime: 75 });
|
||||||
await insertChapter(db, chapterNames[2], { videoID: chapterNamesVid1, startTime: 71, endTime: 76 });
|
await insertChapter(db, chapterNames[2], { videoID: chapterNamesVid1, startTime: 71, endTime: 76 });
|
||||||
|
await insertChapter(db, chapterNames[3], { videoID: chapterNamesVid1, startTime: 72, endTime: 77 });
|
||||||
|
|
||||||
await insertVideoInfo(db, chapterNamesVid1, chapterChannelID);
|
await insertVideoInfo(db, chapterNamesVid1, chapterChannelID);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Search for 'weird'", () => nameSearch("weird", chapterNames[0]));
|
it("Search for 'weird' (2 results)", () => nameSearch("weird", chapterNames[0], 2));
|
||||||
it("Search for 'different'", () => nameSearch("different", chapterNames[1]));
|
it("Search for 'different' (1 result)", () => nameSearch("different", chapterNames[1], 1));
|
||||||
it("Search for 'something'", () => nameSearch("something", chapterNames[2]));
|
it("Search for 'something' (1 result)", () => nameSearch("something", chapterNames[2], 1));
|
||||||
});
|
it("Search for 'unrelated' (0 result)", () => nameSearch("unrelated", null, 0));
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue