fix: search endpoint crashing on User.username reference
User.username doesn't exist - usernames are in Profile model. Now properly searches Profile.username and joins results.
This commit is contained in:
parent
6dd88d4e2d
commit
8990063837
1 changed files with 18 additions and 2 deletions
|
|
@ -47,13 +47,29 @@ def global_search(
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
# Search Users (by username or email)
|
# Search Users (by email or profile username)
|
||||||
users = session.exec(
|
users = session.exec(
|
||||||
select(User)
|
select(User)
|
||||||
.where((col(User.email).ilike(q_str)) | (col(User.username).ilike(q_str)))
|
.where(col(User.email).ilike(q_str))
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
|
# Also search Profiles for username matches
|
||||||
|
from models import Profile
|
||||||
|
profile_matches = session.exec(
|
||||||
|
select(Profile)
|
||||||
|
.where(col(Profile.username).ilike(q_str))
|
||||||
|
.limit(limit)
|
||||||
|
).all()
|
||||||
|
# Add unique users from profile matches
|
||||||
|
existing_user_ids = {u.id for u in users}
|
||||||
|
for p in profile_matches:
|
||||||
|
if p.user_id not in existing_user_ids:
|
||||||
|
user = session.get(User, p.user_id)
|
||||||
|
if user:
|
||||||
|
users.append(user)
|
||||||
|
existing_user_ids.add(user.id)
|
||||||
|
|
||||||
# Search Nicknames
|
# Search Nicknames
|
||||||
nicknames = session.exec(
|
nicknames = session.exec(
|
||||||
select(PerformanceNickname)
|
select(PerformanceNickname)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue