linter fix

This commit is contained in:
Alexander Karpov 2024-12-02 03:17:23 +03:00
parent a2607cd0d0
commit 398820489f
2 changed files with 63 additions and 43 deletions

View File

@ -1,5 +1,5 @@
from functools import wraps
from typing import Any, Dict, Optional
from typing import Any
import requests
import structlog

View File

@ -9,7 +9,7 @@
def search_song(query):
# Split query into potential track and artist parts
parts = [part.strip() for part in query.split('-')]
parts = [part.strip() for part in query.split("-")]
track_query = parts[0]
artist_query = parts[1] if len(parts) > 1 else None
@ -28,51 +28,71 @@ def search_song(query):
# Add artist-specific queries if artist part exists
if artist_query:
should_queries.extend([
ES_Q(
"nested",
path="authors",
query=ES_Q("match_phrase", name={"query": artist_query, "boost": 4})
),
ES_Q(
"nested",
path="authors",
query=ES_Q("match", name={"query": artist_query, "fuzziness": "AUTO", "boost": 3})
),
ES_Q(
"nested",
path="authors",
query=ES_Q("wildcard", name={"value": f"*{artist_query.lower()}*", "boost": 2})
),
])
should_queries.extend(
[
ES_Q(
"nested",
path="authors",
query=ES_Q(
"match_phrase", name={"query": artist_query, "boost": 4}
),
),
ES_Q(
"nested",
path="authors",
query=ES_Q(
"match",
name={"query": artist_query, "fuzziness": "AUTO", "boost": 3},
),
),
ES_Q(
"nested",
path="authors",
query=ES_Q(
"wildcard",
name={"value": f"*{artist_query.lower()}*", "boost": 2},
),
),
]
)
else:
# If no explicit artist, still search in authors but with lower boost
should_queries.extend([
ES_Q(
"nested",
path="authors",
query=ES_Q("match_phrase", name={"query": track_query, "boost": 2}),
),
ES_Q(
"nested",
path="authors",
query=ES_Q("match", name={"query": track_query, "fuzziness": "AUTO", "boost": 1}),
),
])
should_queries.extend(
[
ES_Q(
"nested",
path="authors",
query=ES_Q("match_phrase", name={"query": track_query, "boost": 2}),
),
ES_Q(
"nested",
path="authors",
query=ES_Q(
"match",
name={"query": track_query, "fuzziness": "AUTO", "boost": 1},
),
),
]
)
# Add album queries with lower boost
should_queries.extend([
ES_Q(
"nested",
path="album",
query=ES_Q("match_phrase", name={"query": track_query, "boost": 1.5}),
),
ES_Q(
"nested",
path="album",
query=ES_Q("match", name={"query": track_query, "fuzziness": "AUTO", "boost": 1}),
),
])
should_queries.extend(
[
ES_Q(
"nested",
path="album",
query=ES_Q("match_phrase", name={"query": track_query, "boost": 1.5}),
),
ES_Q(
"nested",
path="album",
query=ES_Q(
"match",
name={"query": track_query, "fuzziness": "AUTO", "boost": 1},
),
),
]
)
# Combine all queries with minimum_should_match=1
search_query = ES_Q("bool", should=should_queries, minimum_should_match=1)