Limited support for fulltext replay search
Some checks failed
Node.js CI / build (16.x) (push) Has been cancelled
Node.js CI / build (20.x) (push) Has been cancelled

This commit is contained in:
Guangcong Luo 2025-02-20 01:57:20 +00:00
parent 843728fe08
commit de9746faba
2 changed files with 23 additions and 4 deletions

View File

@ -893,6 +893,13 @@ export const actions: {[k: string]: QueryHandler} = {
throw new ActionError(`Cannot set both "page" and "before", please choose one method of pagination`);
}
if (params.contains) {
if (Object.keys(params).length > 1) {
throw new ActionError(`Contains can't be combined with other things.`);
}
return Replays.fullSearch(params.contains);
}
const search = {
usernames: usernames,
format: toID(params.format),
@ -923,6 +930,18 @@ export const actions: {[k: string]: QueryHandler} = {
throw new ActionError(`Cannot set both "page" and "before", please choose one method of pagination`);
}
if (params.contains) {
if (Object.keys(params).length > 2) {
throw new ActionError(`Contains can't be combined with other things.`);
}
this.response.setHeader('Content-Type', 'application/json');
try {
return JSON.stringify(await Replays.fullSearch(params.contains));
} catch (e) {
throw new ActionError(`Could not search (timeout?)`);
}
}
const search = {
usernames: usernames,
format: toID(params.format),

View File

@ -213,12 +213,12 @@ export const Replays = new class {
});
if (patterns.length !== 1 && patterns.length !== 2) return Promise.resolve([]);
const secondPattern = patterns.length >= 2 ? SQL`AND log LIKE ${patterns[1]} ` : undefined;
const secondPattern = patterns.length >= 2 ? SQL`AND log LIKE ${patterns[1]} ` : SQL``;
const DAYS = 24 * 60 * 60;
const HOUR = 60 * 60;
return replays.query()`SELECT
uploadtime, id, format, players, rating FROM ps_replays
WHERE private = 0 AND uploadtime > ${time() - 3 * DAYS} AND log LIKE ${patterns[0]} ${secondPattern}
uploadtime, id, format, players, rating FROM replays
WHERE private = 0 AND uploadtime > ${time() - HOUR} AND log LIKE ${patterns[0]} ${secondPattern}
ORDER BY uploadtime DESC LIMIT 50;`.then(this.toReplays);
}