How to close the search bar of TextEditor?

Assuming that you mean the “TextEdit” application: You can close the search bar by hitting esc (or by clicking on the “Done” button).

Closing the search bar with esc works in many other applications as well, e.g. in Mail, Safari, or Xcode.