You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/packages/better-search/script.ts

17 lines
580 B
TypeScript

import nodejieba from 'nodejieba';
import { Pdoc } from 'hydrooj';
import * as document from 'hydrooj/dist/model/document';
export const description = 'Ensure index for peoblem search';
export async function run() {
await document.coll.find({ docType: document.TYPE_PROBLEM }).forEach(async (doc: Pdoc) => {
const segments = nodejieba.cutForSearch(doc.title);
await document.coll.updateOne({ _id: doc._id }, { $set: { search: segments.join(' ') } });
});
}
export const validate = {};
global.Hydro.script.ensureSearch = { run, description, validate };