Refactors search to play nice with hvad and the other apps.