From 4453fd1daa28d09d36b96a311ccd715c4d69537f Mon Sep 17 00:00:00 2001 From: Connor Rhodes Date: Sun, 24 May 2026 16:05:28 +0000 Subject: [PATCH] update script to handle aliases exact and partial --- food-tracking/scripts/food_items.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/food-tracking/scripts/food_items.py b/food-tracking/scripts/food_items.py index 1724ade..d67cc85 100644 --- a/food-tracking/scripts/food_items.py +++ b/food-tracking/scripts/food_items.py @@ -51,10 +51,19 @@ def cmd_get(args): coll, client = get_collection() query = {} if args.name: - query["$or"] = [ - {"name": {"$regex": args.name, "$options": "i"}}, - {"aliases": {"$regex": args.name, "$options": "i"}}, - ] + # Try exact match first (name or any alias), then regex fallback + name_lower = args.name.lower() + exact = coll.find_one({"$or": [ + {"name": name_lower}, + {"aliases": name_lower}, + ]}) + if exact: + query["_id"] = exact["_id"] + else: + query["$or"] = [ + {"name": {"$regex": args.name, "$options": "i"}}, + {"aliases": {"$regex": args.name, "$options": "i"}}, + ] if args.type: query["type"] = {"$regex": args.type, "$options": "i"}