diff --git a/unwind/db.py b/unwind/db.py index 9fa770e..23d3b71 100644 --- a/unwind/db.py +++ b/unwind/db.py @@ -150,9 +150,9 @@ def sql_escape(s: str, char="#"): async def find_ratings( *, - imdb_movie_id: str = None, title: str = None, media_type: str = None, + exact: bool = False, ignore_tv_episodes: bool = False, include_unrated: bool = False, yearcomp: tuple[Literal["<", "=", ">"], int] = None, @@ -166,7 +166,11 @@ async def find_ratings( if title: values["escape"] = "#" escaped_title = sql_escape(title, char=values["escape"]) - values["pattern"] = "%" + "%".join(escaped_title.split()) + "%" + values["pattern"] = ( + "_".join(escaped_title.split()) + if exact + else "%" + "%".join(escaped_title.split()) + "%" + ) conditions.append( f""" ( @@ -227,7 +231,6 @@ async def find_ratings( {','.join(ctes)} SELECT - -- {User._table}.name AS user_name, {Rating._table}.score AS user_score, {Movie._table}.score AS imdb_score, {Movie._table}.imdb_id AS movie_imdb_id, @@ -237,7 +240,6 @@ async def find_ratings( {Movie._table}.release_year AS release_year FROM {source_table} LEFT JOIN {Rating._table} ON {Rating._table}.movie_id={source_table}.movie_id - -- LEFT JOIN {User._table} ON {User._table}.id={Rating._table}.user_id LEFT JOIN {Movie._table} ON {Movie._table}.id={source_table}.movie_id """ diff --git a/unwind/web.py b/unwind/web.py index 3f1e61a..66fd8a9 100644 --- a/unwind/web.py +++ b/unwind/web.py @@ -86,6 +86,7 @@ async def ratings(request): rows = await find_ratings( title=params.get("title"), media_type=params.get("media_type"), + exact=truthy(params.get("exact")), ignore_tv_episodes=truthy(params.get("ignore_tv_episodes")), include_unrated=truthy(params.get("include_unrated")), yearcomp=yearcomp(params["year"]) if "year" in params else None,