From f9fb8dcbf1f3debbc1e73dc0959d304600cc1e08 Mon Sep 17 00:00:00 2001 From: undefined Date: Mon, 24 Aug 2026 15:25:11 +0800 Subject: [PATCH] core&elastic: fix search by id --- packages/elastic/index.ts | 1 + packages/hydrooj/src/handler/problem.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/elastic/index.ts b/packages/elastic/index.ts index ba40afe62..29d896544 100644 --- a/packages/elastic/index.ts +++ b/packages/elastic/index.ts @@ -60,6 +60,7 @@ export default class ElasticSearchService extends Service { pdoc = await ProblemModel.get(domainId, +q.substring(1), ProblemModel.PROJECTION_LIST); if (pdoc) hits.unshift(`${pdoc.domainId}/${pdoc.docId}`); } + if (hits.length > size) hits.pop(); } return { countRelation: typeof res.hits.total === 'number' ? 'eq' : res.hits.total.relation, diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index a2bd37421..112e86a1e 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -67,6 +67,7 @@ const defaultSearch = async (domainId: string, q: string, options?: ProblemSearc pdoc = await problem.get(domainId, +q.substring(1), projection); if (pdoc) pdocs.unshift(pdoc); } + if (pdocs.length > (options.limit || system.get('pagination.problem'))) pdocs.pop(); } return { hits: Array.from(new Set(pdocs.map((i) => `${i.domainId}/${i.docId}`))),