finish the QueryIndex function