convert queries to term ids.