redis fuzzy search needs work, using as fallback for now seems acceptable
This commit is contained in:
parent
fd31e8c16d
commit
dc4f3a763a
@ -75,7 +75,7 @@ class RedisCache:
|
|||||||
song = self.regexes[0].sub(" ", song)
|
song = self.regexes[0].sub(" ", song)
|
||||||
song = self.regexes[1].sub("", song).strip()
|
song = self.regexes[1].sub("", song).strip()
|
||||||
artist = " ".join([f"(%{artist_word}%)" for artist_word in artist.split(" ")])
|
artist = " ".join([f"(%{artist_word}%)" for artist_word in artist.split(" ")])
|
||||||
song = "".join([f"(%{song_word}%)" for song_word in song.split(" ")])
|
song = " ".join([f"(%{song_word}%)" for song_word in song.split(" ")])
|
||||||
return (artist, song)
|
return (artist, song)
|
||||||
|
|
||||||
|
|
||||||
@ -101,14 +101,25 @@ class RedisCache:
|
|||||||
raise RedisException("Lyric search not yet implemented")
|
raise RedisException("Lyric search not yet implemented")
|
||||||
|
|
||||||
if not is_random_search:
|
if not is_random_search:
|
||||||
(artist, song) = self.sanitize_input(artist=artist,
|
logging.debug("Redis: Searching normally first")
|
||||||
song=song)
|
|
||||||
search_res = await self.redis_client.ft().search(Query(
|
search_res = await self.redis_client.ft().search(Query(
|
||||||
f"@artist:{artist} @song:{song}"
|
f"@artist:{artist} @song:{song}"
|
||||||
))
|
))
|
||||||
search_res_out = [(result['id'].split(":",
|
search_res_out = [(result['id'].split(":",
|
||||||
maxsplit=1)[1], dict(json.loads(result['json'])))
|
maxsplit=1)[1], dict(json.loads(result['json'])))
|
||||||
for result in search_res.docs]
|
for result in search_res.docs]
|
||||||
|
if not search_res_out:
|
||||||
|
logging.debug("Redis: Normal search failed, trying with fuzzy search")
|
||||||
|
|
||||||
|
(fuzzy_artist, fuzzy_song) = self.sanitize_input(artist=artist,
|
||||||
|
song=song)
|
||||||
|
search_res = await self.redis_client.ft().search(Query(
|
||||||
|
f"@artist:{fuzzy_artist} @song:{fuzzy_song}"
|
||||||
|
))
|
||||||
|
search_res_out = [(result['id'].split(":",
|
||||||
|
maxsplit=1)[1], dict(json.loads(result['json'])))
|
||||||
|
for result in search_res.docs]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
random_redis_key = await self.redis_client.randomkey()
|
random_redis_key = await self.redis_client.randomkey()
|
||||||
out_id = str(random_redis_key).split(":",
|
out_id = str(random_redis_key).split(":",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user