Sorted search results

Used Levenshtein distance to sort by closest match
This commit is contained in:
JayZed 2024-05-01 16:55:05 -04:00
parent 86b889d3b6
commit d276f9be5e
1 changed files with 5 additions and 0 deletions

View File

@ -8,6 +8,8 @@ from app.database import TableShows, TableMovies, database, select
from ..utils import authenticate
import Levenshtein
api_ns_system_searches = Namespace('System Searches', description='Search for series or movies by name')
@ -61,4 +63,7 @@ class Searches(Resource):
results.append(result)
# sort results by how closely they match the query
results = sorted(results, key=lambda x: Levenshtein.distance(query, x['title']))
return results