mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
优化中文搜索
This commit is contained in:
1 parent
f2f0212947
commit
6eed519407
11 files changed
+91
-9
No files matched your search
@@ -0,0 +1,16 @@
|
||||
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.cut(doc.title);
|
||||
await document.coll.updateOne({ _id: doc._id }, { $set: { search: segments.join(' ') } });
|
||||
});
|
||||
}
|
||||
|
||||
export const validate = {};
|
||||
|
||||
global.Hydro.script.ensureSearch = { run, description, validate };
|
||||
Reference in new issue
Block a user