bump version AGAIN
parent
5d16bc740b
commit
90b2d220c5
@ -1 +0,0 @@
|
|||||||
Ensure index for problem search: 初始化 better-search 插件
|
|
@ -1,17 +0,0 @@
|
|||||||
import nodejieba from 'nodejieba';
|
|
||||||
import * as bus from 'hydrooj/dist/service/bus';
|
|
||||||
|
|
||||||
declare module 'hydrooj' {
|
|
||||||
interface Pdoc {
|
|
||||||
search?: string
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const jiebaHook = async (pdoc) => {
|
|
||||||
if (!pdoc.title) return;
|
|
||||||
const segments = nodejieba.cutForSearch(pdoc.title);
|
|
||||||
pdoc.search = segments.join(' ');
|
|
||||||
};
|
|
||||||
|
|
||||||
bus.on('problem/before-add', jiebaHook);
|
|
||||||
bus.on('problem/before-edit', jiebaHook);
|
|
@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@hydrooj/better-search",
|
|
||||||
"version": "1.0.3",
|
|
||||||
"description": "Enhance Problem Search",
|
|
||||||
"main": "package.json",
|
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
|
||||||
"author": "undefined <i@undefined.moe>",
|
|
||||||
"license": "AGPL-3.0-only",
|
|
||||||
"dependencies": {
|
|
||||||
"nodejieba": "^2.5.1"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
import nodejieba from 'nodejieba';
|
|
||||||
import { Pdoc } from 'hydrooj';
|
|
||||||
import * as document from 'hydrooj/dist/model/document';
|
|
||||||
|
|
||||||
export const description = 'Ensure index for problem 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 };
|
|
Loading…
Reference in New Issue