update script to handle aliases exact and partial
This commit is contained in:
parent
d916c6925b
commit
4453fd1daa
1 changed files with 13 additions and 4 deletions
|
|
@ -51,10 +51,19 @@ def cmd_get(args):
|
||||||
coll, client = get_collection()
|
coll, client = get_collection()
|
||||||
query = {}
|
query = {}
|
||||||
if args.name:
|
if args.name:
|
||||||
query["$or"] = [
|
# Try exact match first (name or any alias), then regex fallback
|
||||||
{"name": {"$regex": args.name, "$options": "i"}},
|
name_lower = args.name.lower()
|
||||||
{"aliases": {"$regex": args.name, "$options": "i"}},
|
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:
|
if args.type:
|
||||||
query["type"] = {"$regex": args.type, "$options": "i"}
|
query["type"] = {"$regex": args.type, "$options": "i"}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue