Fix the search function when using SQLAlchemy