mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 09:38:19 +08:00
feat: search with sonic
This commit is contained in:
1 parent
5d01c81607
commit
43c4bfd8e7
43 files changed
+512
-317
No files matched your search
@@ -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 };
|
||||
Reference in new issue
Block a user