Factor prefixes out of query parser (#649)