mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: allow modifying problem_main query hint
This commit is contained in:
1 file changed
+5
-8
@@ -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) {
|
||||||
|
|||||||
Reference in new issue
Block a user