diff --git a/app/main.py b/app/main.py index d610684..14cbb63 100644 --- a/app/main.py +++ b/app/main.py @@ -663,13 +663,26 @@ def search_tags(): - kind: filter to only include tags of this kind """ from sqlalchemy import case + from app.utils.tag_prefix import parse_kind_prefix - query = request.args.get("q", "").strip().lower() + raw_q = request.args.get("q", "").strip() limit = request.args.get("limit", 10, type=int) exclude_kind = request.args.get("exclude_kind", "").strip() exclude_kinds = [k.strip() for k in exclude_kind.split(",") if k.strip()] include_kind = request.args.get("kind", "").strip() + # Honour the same `kind:rest` shortcut the add-tag input uses, so typing + # "character:mocha" filters to character rows matching "mocha" instead of + # ilike-matching the literal "character:" string against display_name. + # An explicit ?kind= still wins (used by the fandom picker). + if not include_kind: + parsed_kind, parsed_rest = parse_kind_prefix(raw_q) + if parsed_kind is not None: + include_kind = parsed_kind + raw_q = parsed_rest + + query = raw_q.lower() + f = aliased(Tag) display_expr = case( (