From a6740c4faf677c63e96a589e17a1b4bd8936860a Mon Sep 17 00:00:00 2001 From: Alexander-D-Karpov Date: Mon, 22 Apr 2024 14:40:20 +0300 Subject: [PATCH] bug fixes --- akarpov/music/services/search.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/akarpov/music/services/search.py b/akarpov/music/services/search.py index 3029821..153ab64 100644 --- a/akarpov/music/services/search.py +++ b/akarpov/music/services/search.py @@ -12,13 +12,8 @@ def search_song(query): search_query = ES_Q( "bool", should=[ - # Boosting the exact matches using match_phrase - ES_Q("bool", should=[ES_Q("match_phrase", name__exact=query)], boost=3), - ES_Q( - "bool", - should=[ES_Q("match_phrase", name__raw=query.lower())], - boost=2.5, - ), # Case-insensitive exact match with boost + ES_Q("match_phrase", name__exact=query, boost=5), + ES_Q("match_phrase", name__raw=query.lower(), boost=2.5), ES_Q("match", name__russian=query), ES_Q( "multi_match", @@ -30,11 +25,12 @@ def search_song(query): "authors.name.raw^3", "album.name^3", "album.name.raw^3", - "meta.*", # Assuming dynamic mapping for meta fields ], type="best_fields", fuzziness="AUTO", ), + ES_Q("match", meta__lyrics=query, fuzziness="AUTO", boost=0.5), + ES_Q("match", meta__other_field=query, fuzziness="AUTO"), ES_Q( "nested", path="authors", @@ -46,6 +42,17 @@ def search_song(query): ), boost=2, ), + ES_Q( + "nested", + path="album", + query=ES_Q( + "multi_match", + query=query, + fields=["album.name", "album.name.raw"], + fuzziness="AUTO", + ), + boost=2, + ), ES_Q("wildcard", name__raw=f"*{query.lower()}*"), ES_Q("wildcard", meta__raw=f"*{query.lower()}*"), ],