mediasearch: save query on state, proper unbinding
mediasearch: save query on state, proper unbinding

Also, I moved around some definitions. It seems I still don't get
how function hoisting works.

inaes-tic/mbc-caspa,inaes-tic/mbc-caspa