mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2025-02-23 09:30:31 +03:00
linter fix
This commit is contained in:
parent
a2607cd0d0
commit
398820489f
|
@ -1,5 +1,5 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import structlog
|
import structlog
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
def search_song(query):
|
def search_song(query):
|
||||||
# Split query into potential track and artist parts
|
# 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]
|
track_query = parts[0]
|
||||||
artist_query = parts[1] if len(parts) > 1 else None
|
artist_query = parts[1] if len(parts) > 1 else None
|
||||||
|
|
||||||
|
@ -28,26 +28,37 @@ def search_song(query):
|
||||||
|
|
||||||
# Add artist-specific queries if artist part exists
|
# Add artist-specific queries if artist part exists
|
||||||
if artist_query:
|
if artist_query:
|
||||||
should_queries.extend([
|
should_queries.extend(
|
||||||
|
[
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="authors",
|
path="authors",
|
||||||
query=ES_Q("match_phrase", name={"query": artist_query, "boost": 4})
|
query=ES_Q(
|
||||||
|
"match_phrase", name={"query": artist_query, "boost": 4}
|
||||||
|
),
|
||||||
),
|
),
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="authors",
|
path="authors",
|
||||||
query=ES_Q("match", name={"query": artist_query, "fuzziness": "AUTO", "boost": 3})
|
query=ES_Q(
|
||||||
|
"match",
|
||||||
|
name={"query": artist_query, "fuzziness": "AUTO", "boost": 3},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="authors",
|
path="authors",
|
||||||
query=ES_Q("wildcard", name={"value": f"*{artist_query.lower()}*", "boost": 2})
|
query=ES_Q(
|
||||||
|
"wildcard",
|
||||||
|
name={"value": f"*{artist_query.lower()}*", "boost": 2},
|
||||||
),
|
),
|
||||||
])
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# If no explicit artist, still search in authors but with lower boost
|
# If no explicit artist, still search in authors but with lower boost
|
||||||
should_queries.extend([
|
should_queries.extend(
|
||||||
|
[
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="authors",
|
path="authors",
|
||||||
|
@ -56,12 +67,17 @@ def search_song(query):
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="authors",
|
path="authors",
|
||||||
query=ES_Q("match", name={"query": track_query, "fuzziness": "AUTO", "boost": 1}),
|
query=ES_Q(
|
||||||
|
"match",
|
||||||
|
name={"query": track_query, "fuzziness": "AUTO", "boost": 1},
|
||||||
),
|
),
|
||||||
])
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# Add album queries with lower boost
|
# Add album queries with lower boost
|
||||||
should_queries.extend([
|
should_queries.extend(
|
||||||
|
[
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="album",
|
path="album",
|
||||||
|
@ -70,9 +86,13 @@ def search_song(query):
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="album",
|
path="album",
|
||||||
query=ES_Q("match", name={"query": track_query, "fuzziness": "AUTO", "boost": 1}),
|
query=ES_Q(
|
||||||
|
"match",
|
||||||
|
name={"query": track_query, "fuzziness": "AUTO", "boost": 1},
|
||||||
),
|
),
|
||||||
])
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# Combine all queries with minimum_should_match=1
|
# Combine all queries with minimum_should_match=1
|
||||||
search_query = ES_Q("bool", should=should_queries, minimum_should_match=1)
|
search_query = ES_Q("bool", should=should_queries, minimum_should_match=1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user