feat: search with sonic

This commit is contained in:
undefined committed 2021-04-02 00:39:21 +08:00
1 parent 5d01c81607
commit 43c4bfd8e7
43 files changed
+512 -317

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { iterateAllProblem, iterateAllProblemInDomain } from 'hydrooj/dist/upgrade';
import sonic from './service';
export const description = 'Sonic problem search re-index';
export async function run({ domainId }) {
if (domainId) await sonic.flushb('problem', domainId);
else await sonic.flushc('problem');
const cb = async (pdoc) => {
await sonic.push('problem', `${pdoc.domainId}@title`, pdoc.docId.toString(), pdoc.title);
await sonic.push('problem', `${pdoc.domainId}@content`, pdoc.docId.toString(), pdoc.content.toString());
};
if (domainId) await iterateAllProblemInDomain(domainId, ['title', 'content'], cb);
else await iterateAllProblem(['title', 'content'], cb);
return true;
}
export const validate = {
$or: [
{ domainId: 'string' },
{ domainId: 'undefined' },
],
};
global.Hydro.script.ensureSonicSearch = { run, description, validate };