Skip to content

Commit

Permalink
Fix case-insensitive search
Browse files Browse the repository at this point in the history
  • Loading branch information
uittenbroekrobbert committed Aug 15, 2024
1 parent 9049a19 commit 7e8c9d3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions amt/repositories/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def paginate(self, skip: int, limit: int, search: str) -> list[Project]:
if search != "":
search_wildcards = f"%{escape_like(search)}%"
if get_settings().APP_DATABASE_SCHEME == "postgresql":
statement = statement.filter(Project.name.like(search_wildcards) | Project.name.match(search))
statement = statement.filter(Project.name.ilike(search_wildcards) | Project.name.match(search))
else:
statement = statement.filter(Project.name.like(search_wildcards))
statement = statement.filter(Project.name.ilike(search_wildcards))
statement = statement.order_by(func.lower(Project.name)).offset(skip).limit(limit)
return list(self.session.execute(statement).scalars())
except Exception as e:
Expand Down
6 changes: 6 additions & 0 deletions tests/repositories/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def test_search_multiple(db: DatabaseTestUtils):
assert result[1].name == "aba"


def test_search_no_results(db: DatabaseTestUtils):
project_repository = ProjectsRepository(db.get_session())
result = project_repository.paginate(skip=0, limit=4, search="A")
assert len(result) == 0


def test_raises_exception(db: DatabaseTestUtils):
db.given([default_project()])
project_repository = ProjectsRepository(db.get_session())
Expand Down

0 comments on commit 7e8c9d3

Please # to comment.