优化中文搜索

This commit is contained in:
undefined committed 2020-09-06 12:12:54 +08:00
1 parent f2f0212947
commit 6eed519407
11 files changed
+91 -9

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
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.cut(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.cut($set.title);
$set.search = segments.join(' ');
});