Split query translation into a query term generator and main loop.