sort the query terms (required to make range queries work consistently)