Code for query expansion.