mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +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 {
|
import {
|
||||||
Context, DomainModel, iterateAllProblem, iterateAllProblemInDomain,
|
Context, DomainModel, iterateAllProblem, iterateAllProblemInDomain,
|
||||||
Logger, Schema, SystemModel,
|
Logger, ProblemModel, Schema, SystemModel,
|
||||||
} from 'hydrooj';
|
} from 'hydrooj';
|
||||||
import { SonicService } from './service';
|
import { SonicService } from './service';
|
||||||
|
|
||||||
@@ -11,12 +11,22 @@ export function apply(ctx: Context) {
|
|||||||
|
|
||||||
global.Hydro.lib.problemSearch = async (domainId, query, opts) => {
|
global.Hydro.lib.problemSearch = async (domainId, query, opts) => {
|
||||||
const limit = opts?.limit || SystemModel.get('pagination.problem');
|
const limit = opts?.limit || SystemModel.get('pagination.problem');
|
||||||
const ids = await ctx.sonic.query('problem', `${domainId}@title`, query, { limit });
|
let hits = 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 }));
|
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 {
|
return {
|
||||||
countRelation: ids.length >= limit ? 'gte' : 'eq',
|
countRelation: hits.length >= limit ? 'gte' : 'eq',
|
||||||
total: ids.length,
|
total: hits.length,
|
||||||
hits: ids,
|
hits,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/sonic",
|
"name": "@hydrooj/sonic",
|
||||||
"version": "1.3.1",
|
"version": "1.3.2",
|
||||||
"description": "Sonic search service",
|
"description": "Sonic search service",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
"preferUnplugged": true,
|
"preferUnplugged": true,
|
||||||
|
|||||||
Reference in new issue
Block a user