add exact matching option
This commit is contained in:
parent
c823c51721
commit
1038b4eaff
2 changed files with 7 additions and 4 deletions
10
unwind/db.py
10
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
|
||||
"""
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue