Example usage for org.apache.lucene.facet.taxonomy.directory DirectoryTaxonomyReader getPath

List of usage examples for org.apache.lucene.facet.taxonomy.directory DirectoryTaxonomyReader getPath

Introduction

In this page you can find the example usage for org.apache.lucene.facet.taxonomy.directory DirectoryTaxonomyReader getPath.

Prototype

@Override
    public FacetLabel getPath(int ordinal) throws IOException 

Source Link

Usage

From source file:org.meresco.lucene.Lucene.java

License:Open Source License

public List<String> drilldownFieldnames(int limit, String dim, String... path) throws Exception {
    SearcherAndTaxonomy reference = data.getManager().acquire();
    try {/*from w w w .  j a v a 2 s .  c o  m*/
        DirectoryTaxonomyReader taxoReader = reference.taxonomyReader;
        int parentOrdinal = dim == null ? TaxonomyReader.ROOT_ORDINAL : taxoReader.getOrdinal(dim, path);
        ChildrenIterator childrenIter = taxoReader.getChildren(parentOrdinal);
        List<String> fieldnames = new ArrayList<String>();
        while (true) {
            int ordinal = childrenIter.next();
            if (ordinal == TaxonomyReader.INVALID_ORDINAL)
                break;
            String[] components = taxoReader.getPath(ordinal).components;
            fieldnames.add(components[components.length - 1]);
            if (fieldnames.size() >= limit)
                break;
        }
        return fieldnames;
    } finally {
        data.getManager().release(reference);
    }
}