Automatically generate the hierarchical index