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

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

Introduction

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

Prototype

public ChildrenIterator getChildren(final int ordinal) throws IOException 

Source Link

Document

Returns an iterator over the children of the given ordinal.

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 {// w w  w . j  a  va  2s  . 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);
    }
}