Prevent uninitialized warnings on search result pages with no query

Fixes issues #29699
Merge branch '4.0/avoid-warnings-on-empty-search' into 4.0-trunk