mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
better-search: use cutForSearch
This commit is contained in:
1 parent
f75c12f4bd
commit
dbc5fff09f
3 files changed
+4
-4
No files matched your search
@@ -12,12 +12,12 @@ declare module 'hydrooj' {
|
||||
bus.on('document/add', async (doc) => {
|
||||
if (doc.type !== document.TYPE_PROBLEM) return;
|
||||
const pdoc = doc as Pdoc;
|
||||
const segments = nodejieba.cut(pdoc.title);
|
||||
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.cut($set.title);
|
||||
const segments = nodejieba.cutForSearch($set.title);
|
||||
$set.search = segments.join(' ');
|
||||
});
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/better-search",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "Enhance Problem Search",
|
||||
"main": "package.json",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -6,7 +6,7 @@ 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);
|
||||
const segments = nodejieba.cutForSearch(doc.title);
|
||||
await document.coll.updateOne({ _id: doc._id }, { $set: { search: segments.join(' ') } });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user