mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +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",
|
||||
"saslprep": "^1.0.3",
|
||||
"schemastery": "^3.11.1",
|
||||
"search-query-parser": "^1.6.0",
|
||||
"semver": "^7.5.4",
|
||||
"serialize-javascript": "^6.0.1",
|
||||
"superagent": "^8.0.9",
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
} from 'lodash';
|
||||
import { Filter, ObjectId } from 'mongodb';
|
||||
import { nanoid } from 'nanoid';
|
||||
import parser from 'search-query-parser';
|
||||
import { sortFiles, streamToBuffer } from '@hydrooj/utils/lib/utils';
|
||||
import {
|
||||
BadRequestError, ContestNotAttendedError, ContestNotEndedError, ContestNotFoundError, ContestNotLiveError,
|
||||
@@ -144,10 +145,17 @@ export class ProblemMainHandler extends Handler {
|
||||
let sort: string[];
|
||||
let fail = false;
|
||||
let pcountRelation = 'eq';
|
||||
const category = flattenDeep(q.split(' ')
|
||||
.filter((i) => i.startsWith('category:'))
|
||||
.map((i) => i.split('category:')[1]?.split(',')));
|
||||
const text = q.split(' ').filter((i) => !i.startsWith('category:')).join(' ');
|
||||
const parsed = parser.parse(q, {
|
||||
keywords: ['category', 'difficulty'],
|
||||
offsets: false,
|
||||
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 (text) category.push(text);
|
||||
if (category.length) this.UiContext.extraTitleContent = category.join(',');
|
||||
@@ -214,7 +222,6 @@ export class ProblemMainHandler extends Handler {
|
||||
pcountRelation,
|
||||
pdocs,
|
||||
psdict,
|
||||
category: category.join(','),
|
||||
qs: q,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
{% import "components/problem.html" as problem with context %}
|
||||
{% extends "layout/basic.html" %}
|
||||
{% block content %}
|
||||
{{ set(UiContext, {
|
||||
currentCategory: category
|
||||
}) }}
|
||||
<div class="row">
|
||||
<div class="medium-9 columns">
|
||||
<div class="section display-mode">
|
||||
|
||||
Reference in new issue
Block a user