mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: support search by difficulty
This commit is contained in:
3 files changed
+13
-8
No files matched your search
@@ -49,6 +49,7 @@
|
|||||||
"require-resolve-hook": "^1.1.0",
|
"require-resolve-hook": "^1.1.0",
|
||||||
"saslprep": "^1.0.3",
|
"saslprep": "^1.0.3",
|
||||||
"schemastery": "^3.11.1",
|
"schemastery": "^3.11.1",
|
||||||
|
"search-query-parser": "^1.6.0",
|
||||||
"semver": "^7.5.4",
|
"semver": "^7.5.4",
|
||||||
"serialize-javascript": "^6.0.1",
|
"serialize-javascript": "^6.0.1",
|
||||||
"superagent": "^8.0.9",
|
"superagent": "^8.0.9",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
} from 'lodash';
|
} from 'lodash';
|
||||||
import { Filter, ObjectId } from 'mongodb';
|
import { Filter, ObjectId } from 'mongodb';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
|
import parser from 'search-query-parser';
|
||||||
import { sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
import { sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
||||||
import {
|
import {
|
||||||
BadRequestError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError, ContestNotLiveError,
|
BadRequestError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError, ContestNotLiveError,
|
||||||
@@ -144,10 +145,17 @@ export class ProblemMainHandler extends Handler {
|
|||||||
let sort: string[];
|
let sort: string[];
|
||||||
let fail = false;
|
let fail = false;
|
||||||
let pcountRelation = 'eq';
|
let pcountRelation = 'eq';
|
||||||
const category = flattenDeep(q.split(' ')
|
const parsed = parser.parse(q, {
|
||||||
.filter((i) => i.startsWith('category:'))
|
keywords: ['category', 'difficulty'],
|
||||||
.map((i) => i.split('category:')[1]?.split(',')));
|
offsets: false,
|
||||||
const text = q.split(' ').filter((i) => !i.startsWith('category:')).join(' ');
|
alwaysArray: true,
|
||||||
|
tokenize: true,
|
||||||
|
});
|
||||||
|
const category = parsed.category || [];
|
||||||
|
const text = (parsed.text || []).join(' ');
|
||||||
|
if (parsed.difficulty?.every((i) => Number.isSafeInteger(+i))) {
|
||||||
|
query.difficulty = { $in: parsed.difficulty.map(Number) };
|
||||||
|
}
|
||||||
if (category.length) query.$and = category.map((tag) => ({ tag }));
|
if (category.length) query.$and = category.map((tag) => ({ tag }));
|
||||||
if (text) category.push(text);
|
if (text) category.push(text);
|
||||||
if (category.length) this.UiContext.extraTitleContent = category.join(',');
|
if (category.length) this.UiContext.extraTitleContent = category.join(',');
|
||||||
@@ -214,7 +222,6 @@ export class ProblemMainHandler extends Handler {
|
|||||||
pcountRelation,
|
pcountRelation,
|
||||||
pdocs,
|
pdocs,
|
||||||
psdict,
|
psdict,
|
||||||
category: category.join(','),
|
|
||||||
qs: q,
|
qs: q,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
{% import "components/problem.html" as problem with context %}
|
{% import "components/problem.html" as problem with context %}
|
||||||
{% extends "layout/basic.html" %}
|
{% extends "layout/basic.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{{ set(UiContext, {
|
|
||||||
currentCategory: category
|
|
||||||
}) }}
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="medium-9 columns">
|
<div class="medium-9 columns">
|
||||||
<div class="section display-mode">
|
<div class="section display-mode">
|
||||||
|
|||||||
Reference in new issue
Block a user