Fixed candidate index creation/test, and added search function.