How to hide collections when empty

I have a search box in the header where when typed in, collections are shown based on the text entered. I would like to remove the collection block if such a collection does not exist.

image

image