core: allow modifying problem_main query hint

This commit is contained in:
undefined committed 2024-11-24 18:11:38 +08:00
1 parent 65f6153d13
commit 29556f964d
1 file changed
+5 -8
+5 -8
View File
@@ -81,6 +81,7 @@ export interface QueryContext {
text: string; text: string;
total: number; total: number;
fail: boolean; fail: boolean;
hint: string;
} }
export class ProblemMainHandler extends Handler { export class ProblemMainHandler extends Handler {
@@ -93,6 +94,7 @@ export class ProblemMainHandler extends Handler {
text: '', text: '',
total: 0, total: 0,
fail: false, fail: false,
hint: 'sort',
}; };
@param('page', Types.PositiveInt, true) @param('page', Types.PositiveInt, true)
@@ -134,13 +136,8 @@ export class ProblemMainHandler extends Handler {
total = result.total; total = result.total;
this.queryContext.pcountRelation = result.countRelation; this.queryContext.pcountRelation = result.countRelation;
if (!result.hits.length) this.queryContext.fail = true; if (!result.hits.length) this.queryContext.fail = true;
query.$and ||= []; query.docId = { $in: result.hits.map((t) => +t.split('/')[1]) };
query.$and.push({ this.queryContext.hint = 'basic';
$or: result.hits.map((i) => {
const [did, docId] = i.split('/');
return { domainId: did, docId: +docId };
}),
});
this.queryContext.sort = result.hits; this.queryContext.sort = result.hits;
} }
const sort = this.queryContext.sort; const sort = this.queryContext.sort;
@@ -150,7 +147,7 @@ export class ProblemMainHandler extends Handler {
? [[], 0, 0] ? [[], 0, 0]
: await this.paginate( : await this.paginate(
problem.getMulti(domainId, query, quick ? ['title', 'pid', 'domainId', 'docId'] : undefined) problem.getMulti(domainId, query, quick ? ['title', 'pid', 'domainId', 'docId'] : undefined)
.sort({ sort: 1, docId: 1 }).hint('sort'), .sort({ sort: 1, docId: 1 }).hint(this.queryContext.hint),
sort.length ? 1 : page, limit, sort.length ? 1 : page, limit,
); );
if (total) { if (total) {