fix bug for queries without codebook