Make pre-commit happy
This commit is contained in:
parent
48592ea626
commit
151ad19f3d
|
|
@ -231,18 +231,26 @@ class QueryBuilder:
|
|||
def _build_tag_query(tag):
|
||||
"""build per-tag query clause"""
|
||||
if "?" in tag:
|
||||
raise ValueError("unsupported wildcard for tag: only trailing * is supported")
|
||||
raise ValueError(
|
||||
"unsupported wildcard for tag: only trailing * is supported"
|
||||
)
|
||||
|
||||
if "*" in tag:
|
||||
if tag.count("*") != 1 or not tag.endswith("*") or tag.startswith("*"):
|
||||
if (
|
||||
tag.count("*") != 1
|
||||
or not tag.endswith("*")
|
||||
or tag.startswith("*")
|
||||
):
|
||||
raise ValueError(
|
||||
"unsupported wildcard for tag: only trailing * is supported"
|
||||
"unsupported wildcard for tag: "
|
||||
"only trailing * is supported"
|
||||
)
|
||||
|
||||
prefix_value = tag[:-1]
|
||||
if not prefix_value:
|
||||
raise ValueError(
|
||||
"unsupported wildcard for tag: only trailing * is supported"
|
||||
"unsupported wildcard for tag: "
|
||||
"only trailing * is supported"
|
||||
)
|
||||
|
||||
return {"prefix": {"tags.keyword": {"value": prefix_value}}}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
"""tests for search DSL parsing/building"""
|
||||
|
||||
import pytest
|
||||
|
||||
from common.src.searching import SearchParser
|
||||
|
||||
|
||||
|
|
@ -52,9 +51,7 @@ def test_tag_prefix_wildcard_builds_prefix_query():
|
|||
|
||||
def test_tag_invalid_wildcard_rejected():
|
||||
"""leading wildcard is not supported"""
|
||||
with pytest.raises(
|
||||
ValueError, match=r"only trailing \* is supported"
|
||||
):
|
||||
with pytest.raises(ValueError, match=r"only trailing \* is supported"):
|
||||
SearchParser("tag:*music").run()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,11 @@ from common.src.searching import SearchForm
|
|||
from common.src.ta_redis import RedisArchivist
|
||||
from common.src.watched import WatchState
|
||||
from common.views_base import AdminOnly, ApiBaseView
|
||||
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
|
||||
from drf_spectacular.utils import (
|
||||
OpenApiParameter,
|
||||
OpenApiResponse,
|
||||
extend_schema,
|
||||
)
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from task.tasks import check_reindex
|
||||
|
|
|
|||
|
|
@ -25,18 +25,20 @@ const EmptySearchResponse: ApiResponseType<SearchResultsType> = {
|
|||
status: 200,
|
||||
};
|
||||
|
||||
const Search = () => {
|
||||
type SearchInnerProps = {
|
||||
queryParam: string | null;
|
||||
videoId: string | null;
|
||||
};
|
||||
|
||||
const SearchInner = ({ queryParam, videoId }: SearchInnerProps) => {
|
||||
const { userConfig } = useUserConfigStore();
|
||||
const [searchParams] = useSearchParams();
|
||||
const videoId = searchParams.get('videoId');
|
||||
const queryParam = searchParams.get('query');
|
||||
|
||||
const viewVideos = userConfig.view_style_home;
|
||||
const viewChannels = userConfig.view_style_channel;
|
||||
const viewPlaylists = userConfig.view_style_playlist;
|
||||
const gridItems = userConfig.grid_items || 3;
|
||||
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [searchTerm, setSearchTerm] = useState(() => queryParam ?? '');
|
||||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState<string>('');
|
||||
const [searchResults, setSearchResults] = useState<ApiResponseType<SearchResultsType>>();
|
||||
|
||||
|
|
@ -73,12 +75,6 @@ const Search = () => {
|
|||
setRefresh(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (queryParam !== null) {
|
||||
setSearchTerm(queryParam);
|
||||
}
|
||||
}, [queryParam]);
|
||||
|
||||
useEffect(() => {
|
||||
const handler = setTimeout(() => {
|
||||
setDebouncedSearchTerm(searchTerm);
|
||||
|
|
@ -177,4 +173,14 @@ const Search = () => {
|
|||
);
|
||||
};
|
||||
|
||||
const Search = () => {
|
||||
const [searchParams] = useSearchParams();
|
||||
const videoId = searchParams.get('videoId');
|
||||
const queryParam = searchParams.get('query');
|
||||
|
||||
return (
|
||||
<SearchInner key={queryParam ?? '__no_query__'} queryParam={queryParam} videoId={videoId} />
|
||||
);
|
||||
};
|
||||
|
||||
export default Search;
|
||||
|
|
|
|||
Loading…
Reference in New Issue