Fix index purge, plus add test for it.