mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
sonic: search by id
This commit is contained in:
2 files changed
+17
-7
No files matched your search
+16
-6
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
Context, DomainModel, iterateAllProblem, iterateAllProblemInDomain,
|
||||
Logger, Schema, SystemModel,
|
||||
Logger, ProblemModel, Schema, SystemModel,
|
||||
} from 'hydrooj';
|
||||
import { SonicService } from './service';
|
||||
|
||||
@@ -11,12 +11,22 @@ export function apply(ctx: Context) {
|
||||
|
||||
global.Hydro.lib.problemSearch = async (domainId, query, opts) => {
|
||||
const limit = opts?.limit || SystemModel.get('pagination.problem');
|
||||
const ids = await ctx.sonic.query('problem', `${domainId}@title`, query, { limit });
|
||||
if (limit - ids.length > 0) ids.push(...await ctx.sonic.query('problem', `${domainId}@content`, query, { limit: limit - ids.length }));
|
||||
let hits = await ctx.sonic.query('problem', `${domainId}@title`, query, { limit });
|
||||
if (!opts.skip) {
|
||||
let pdoc = await ProblemModel.get(domainId, +query || query, ProblemModel.PROJECTION_LIST);
|
||||
if (pdoc) {
|
||||
hits = hits.filter((i) => i !== `${pdoc.domainId}/${pdoc.docId}`);
|
||||
hits.unshift(`${pdoc.domainId}/${pdoc.docId}`);
|
||||
} else if (/^P\d+$/.test(query)) {
|
||||
pdoc = await ProblemModel.get(domainId, +query.substring(1), ProblemModel.PROJECTION_LIST);
|
||||
if (pdoc) hits.unshift(`${pdoc.domainId}/${pdoc.docId}`);
|
||||
}
|
||||
}
|
||||
if (limit - hits.length > 0) hits.push(...await ctx.sonic.query('problem', `${domainId}@content`, query, { limit: limit - hits.length }));
|
||||
return {
|
||||
countRelation: ids.length >= limit ? 'gte' : 'eq',
|
||||
total: ids.length,
|
||||
hits: ids,
|
||||
countRelation: hits.length >= limit ? 'gte' : 'eq',
|
||||
total: hits.length,
|
||||
hits,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@hydrooj/sonic",
|
||||
"version": "1.3.1",
|
||||
"version": "1.3.2",
|
||||
"description": "Sonic search service",
|
||||
"main": "index.ts",
|
||||
"preferUnplugged": true,
|
||||
|
||||
Reference in new issue
Block a user