redis fuzzy search needs work, using as fallback for now seems acceptable
This commit is contained in:
		@@ -75,7 +75,7 @@ class RedisCache:
 | 
			
		||||
        song = self.regexes[0].sub(" ", song)
 | 
			
		||||
        song = self.regexes[1].sub("", song).strip()
 | 
			
		||||
        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)        
 | 
			
		||||
        
 | 
			
		||||
    
 | 
			
		||||
@@ -101,14 +101,25 @@ class RedisCache:
 | 
			
		||||
                raise RedisException("Lyric search not yet implemented")
 | 
			
		||||
            
 | 
			
		||||
            if not is_random_search:
 | 
			
		||||
                (artist, song) = self.sanitize_input(artist=artist,
 | 
			
		||||
                                                    song=song)
 | 
			
		||||
                logging.debug("Redis: Searching normally first")
 | 
			
		||||
                search_res = await self.redis_client.ft().search(Query(
 | 
			
		||||
                    f"@artist:{artist} @song:{song}"
 | 
			
		||||
                    ))
 | 
			
		||||
                search_res_out = [(result['id'].split(":",
 | 
			
		||||
                                                      maxsplit=1)[1], dict(json.loads(result['json'])))
 | 
			
		||||
                                  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:
 | 
			
		||||
                random_redis_key = await self.redis_client.randomkey()
 | 
			
		||||
                out_id = str(random_redis_key).split(":",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user