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.
24 lines
709 B
TypeScript
24 lines
709 B
TypeScript
import nodejieba from 'nodejieba';
|
|
import { Pdoc } from 'hydrooj';
|
|
import * as document from 'hydrooj/dist/model/document';
|
|
import * as bus from 'hydrooj/dist/service/bus';
|
|
|
|
declare module 'hydrooj' {
|
|
interface Pdoc {
|
|
search?: string
|
|
}
|
|
}
|
|
|
|
bus.on('document/add', async (doc) => {
|
|
if (doc.type !== document.TYPE_PROBLEM) return;
|
|
const pdoc = doc as Pdoc;
|
|
const segments = nodejieba.cutForSearch(pdoc.title);
|
|
pdoc.search = segments.join(' ');
|
|
});
|
|
|
|
bus.on('document/set', async (domainId, docType, docId, $set) => {
|
|
if (docType !== document.TYPE_PROBLEM || !$set.title) return;
|
|
const segments = nodejieba.cutForSearch($set.title);
|
|
$set.search = segments.join(' ');
|
|
});
|