A learning framework for nearest neighbor search