This commit is contained in:
undefined committed 2021-08-10 21:37:29 +08:00
1 parent 63bf550311
commit d9f13feade
17 files changed
+54 -34

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/sonic",
"version": "1.1.0",
"version": "1.1.1",
"description": "Sonic search service",
"main": "service.js",
"typings": "service.d.ts",
+8 -3
View File
@@ -3,12 +3,17 @@ import sonic from './service';
export const description = 'Sonic problem search re-index';
export async function run({ domainId }) {
export async function run({ domainId }, report) {
if (domainId) await sonic.flushb('problem', domainId);
else await sonic.flushc('problem');
let i = 0;
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());
i++;
if (!(i % 1000)) report({ message: `${i} problems indexed` });
await Promise.all([
sonic.push('problem', `${pdoc.domainId}@title`, pdoc.docId.toString(), pdoc.title),
sonic.push('problem', `${pdoc.domainId}@content`, pdoc.docId.toString(), pdoc.content.toString()),
]).catch((e) => console.log(`${pdoc.domainId}/${pdoc.docId}`, e));
};
if (domainId) await iterateAllProblemInDomain(domainId, ['title', 'content'], cb);
else await iterateAllProblem(['title', 'content'], cb);