search: clean internal query representation
Created by: rvantonder
Currently the value of r.Query can vary when we evaluate subexpressions, but does not if the query is so-called basic. Our internal state should capture the structure of a Query so we don't have to do various tests against the original query string for things like alert (see #18257).