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

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

Introduction

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

Prototype

public int getOrdinal(String dim, String[] path) throws IOException 

Source Link

Document

Returns ordinal for the dim + path.

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. ja  v a  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);
    }
}