mirror of
https://github.com/Alexander-D-Karpov/akarpov
synced 2024-11-22 00:26:36 +03:00
updated music search
This commit is contained in:
parent
4a2b86509e
commit
7e188865cc
|
@ -35,7 +35,8 @@ class SongDocument(Document):
|
||||||
name = fields.TextField(
|
name = fields.TextField(
|
||||||
attr="name",
|
attr="name",
|
||||||
fields={
|
fields={
|
||||||
"raw": fields.KeywordField(normalizer="lowercase"),
|
"raw": fields.KeywordField(),
|
||||||
|
"exact": fields.KeywordField(normalizer="lowercase"),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
suggest = fields.CompletionField()
|
suggest = fields.CompletionField()
|
||||||
|
|
|
@ -12,8 +12,11 @@ def search_song(query):
|
||||||
search_query = ES_Q(
|
search_query = ES_Q(
|
||||||
"bool",
|
"bool",
|
||||||
should=[
|
should=[
|
||||||
ES_Q("match", name=query),
|
ES_Q("match_phrase", name__exact=query, boost=3), # Boost for exact matches
|
||||||
ES_Q("match", name__russian=query),
|
ES_Q(
|
||||||
|
"match_phrase", name__raw=query.lower(), boost=2.5
|
||||||
|
), # Case-insensitive exact match
|
||||||
|
ES_Q("match", name__russian=query), # Match in Russian field
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"multi_match",
|
"multi_match",
|
||||||
query=query,
|
query=query,
|
||||||
|
@ -24,7 +27,7 @@ def search_song(query):
|
||||||
"authors.name.raw^3",
|
"authors.name.raw^3",
|
||||||
"album.name^3",
|
"album.name^3",
|
||||||
"album.name.raw^3",
|
"album.name.raw^3",
|
||||||
"name.raw^2",
|
"meta.*",
|
||||||
],
|
],
|
||||||
type="best_fields",
|
type="best_fields",
|
||||||
fuzziness="AUTO",
|
fuzziness="AUTO",
|
||||||
|
@ -38,8 +41,8 @@ def search_song(query):
|
||||||
fields=["authors.name", "authors.name.raw"],
|
fields=["authors.name", "authors.name.raw"],
|
||||||
fuzziness="AUTO",
|
fuzziness="AUTO",
|
||||||
),
|
),
|
||||||
|
boost=2,
|
||||||
),
|
),
|
||||||
ES_Q("wildcard", name__raw=f"*{query.lower()}*"),
|
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"nested",
|
||||||
path="album",
|
path="album",
|
||||||
|
@ -49,13 +52,14 @@ def search_song(query):
|
||||||
fields=["album.name", "album.name.raw"],
|
fields=["album.name", "album.name.raw"],
|
||||||
fuzziness="AUTO",
|
fuzziness="AUTO",
|
||||||
),
|
),
|
||||||
|
boost=2,
|
||||||
),
|
),
|
||||||
ES_Q(
|
ES_Q(
|
||||||
"nested",
|
"wildcard", name__raw=f"*{query.lower()}*"
|
||||||
path="album",
|
), # Wildcard search for partial matches
|
||||||
query=ES_Q("wildcard", album__name__raw=f"*{query.lower()}*"),
|
ES_Q(
|
||||||
),
|
"wildcard", meta__raw=f"*{query.lower()}*"
|
||||||
ES_Q("wildcard", meta__raw=f"*{query.lower()}*"),
|
), # Wildcard search in meta fields
|
||||||
],
|
],
|
||||||
minimum_should_match=1,
|
minimum_should_match=1,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user