Fixed query_by_sampling method to use generic q wrapper.