mirror of
https://github.com/smogon/pokemon-showdown-loginserver.git
synced 2026-03-21 17:34:38 -05:00
Limited support for fulltext replay search
This commit is contained in:
parent
843728fe08
commit
de9746faba
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user