feat: search with sonic

This commit is contained in:
undefined committed 2021-04-02 00:39:21 +08:00
1 parent 5d01c81607
commit 43c4bfd8e7
43 files changed
+512 -317

No files matched your search

+5 -11
View File
@@ -1,6 +1,4 @@
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' {
@@ -9,15 +7,11 @@ declare module 'hydrooj' {
}
}
bus.on('document/add', async (doc) => {
if (doc.type !== document.TYPE_PROBLEM) return;
const pdoc = doc as Pdoc;
const jiebaHook = async (pdoc) => {
if (!pdoc.title) return;
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(' ');
});
bus.on('problem/before-add', jiebaHook);
bus.on('problem/before-edit', jiebaHook);
+1 -9
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/better-search",
"version": "1.0.2",
"version": "1.0.3",
"description": "Enhance Problem Search",
"main": "package.json",
"repository": "https://github.com/hydro-dev/Hydro.git",
@@ -8,13 +8,5 @@
"license": "AGPL-3.0-only",
"dependencies": {
"nodejieba": "^2.5.1"
},
"devDependencies": {},
"peerDependencies": {
"hydrooj": "^2.13.2"
},
"scripts": {
"build": "tsc",
"lint": "eslint . --ext ts --fix"
}
}