Fix two bugs in search API endpoint.