Example usage for org.apache.lucene.facet.taxonomy TaxonomyReader ROOT_ORDINAL

List of usage examples for org.apache.lucene.facet.taxonomy TaxonomyReader ROOT_ORDINAL

Introduction

In this page you can find the example usage for org.apache.lucene.facet.taxonomy TaxonomyReader ROOT_ORDINAL.

Prototype

int ROOT_ORDINAL

To view the source code for org.apache.lucene.facet.taxonomy TaxonomyReader ROOT_ORDINAL.

Click Source Link

Document

The root category (the category with the empty path) always has the ordinal 0, to which we give a name ROOT_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 {/*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);
    }
}