Fix the search SQL logic and improve the indentation.