One other thought -- I don't feel too strongly on this though -- this might read more easily if the creation of `stringRanges` were hoisted out into a utility function.  Something like `makeSimplePrefixMatch()`.  (I could imagine doing a similar cleanup for the degenerate `!query` case just above here too, although the code there is simpler so it'd be less of a win).