Extracting terms from query