Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive search #35

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions rating_api/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from sqlalchemy import UUID, DateTime
from sqlalchemy import Enum as DbEnum
from sqlalchemy import ForeignKey, Integer, String, and_, or_, true
from sqlalchemy import ForeignKey, Integer, String, and_, func, or_, true
from sqlalchemy.ext.hybrid import hybrid_method
from sqlalchemy.orm import Mapped, mapped_column, relationship

Expand Down Expand Up @@ -40,8 +40,14 @@ def search(self, query: str) -> bool:
response = true
query = query.split(' ')
for q in query:
q = q.lower()
response = and_(
response, or_(self.first_name.contains(q), self.middle_name.contains(q), self.last_name.contains(q))
response,
or_(
func.lower(self.first_name).contains(q),
func.lower(self.middle_name).contains(q),
func.lower(self.last_name).contains(q),
),
)
return response

Expand Down
Loading