Create wrapper query that makes delegate safer

This creates a wrapper query that statically inspects the query that it wraps
and removes slow constructs.  In this commit its only going to handle large
phrase queries or queries that contain too many phrase queries.

Change-Id: I9560105c31d429df24d13232222740acba9b8e9a