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

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

Introduction

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

Prototype

int INVALID_ORDINAL

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

Click Source Link

Document

Ordinals are always non-negative, so a negative ordinal can be used to signify an error.

Usage

From source file:org.exist.indexing.lucene.QueryFacetCollector.java

License:Open Source License

private List<FacetResult> accumulate() throws IOException {

    // aggregate facets per category list (usually only one category list)
    FacetsAggregator aggregator = getAggregator();
    for (CategoryListParams clp : getCategoryLists()) {
        for (MatchingDocs md : matchingDocs) {
            aggregator.aggregate(md, clp, facetArrays);
        }/*from   w  ww . j a v  a  2 s .co m*/
    }

    ParallelTaxonomyArrays arrays = taxonomyReader.getParallelTaxonomyArrays();

    // compute top-K
    final int[] children = arrays.children();
    final int[] siblings = arrays.siblings();
    List<FacetResult> res = new ArrayList<>();
    for (FacetRequest fr : searchParams.facetRequests) {
        int rootOrd = taxonomyReader.getOrdinal(fr.categoryPath);
        // category does not exist
        if (rootOrd == TaxonomyReader.INVALID_ORDINAL) {
            // Add empty FacetResult
            res.add(emptyResult(rootOrd, fr));
            continue;
        }
        CategoryListParams clp = searchParams.indexingParams.getCategoryListParams(fr.categoryPath);
        // someone might ask to aggregate ROOT category
        if (fr.categoryPath.length > 0) {
            OrdinalPolicy ordinalPolicy = clp.getOrdinalPolicy(fr.categoryPath.components[0]);
            if (ordinalPolicy == OrdinalPolicy.NO_PARENTS) {
                // rollup values
                aggregator.rollupValues(fr, rootOrd, children, siblings, facetArrays);
            }
        }

        FacetResultsHandler frh = createFacetResultsHandler(fr);
        res.add(frh.compute());
    }
    return res;
}

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 ww .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);
    }
}

From source file:org.meresco.lucene.search.MerescoTaxonomyFacetCounts.java

License:Open Source License

private int rollup(int ord) {
    int sum = 0;/*from www  . j  a v a 2  s  . c  o  m*/
    while (ord != TaxonomyReader.INVALID_ORDINAL) {
        int childValue = values[ord] + rollup(children[ord]);
        values[ord] = childValue;
        sum += childValue;
        ord = siblings[ord];
    }
    return sum;
}

From source file:org.meresco.lucene.search.MerescoTaxonomyFacetCounts.java

License:Open Source License

@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
    if (topN <= 0) {
        throw new IllegalArgumentException("topN must be > 0 (got: " + topN + ")");
    }/*from w  w w. j  av  a2  s .co m*/
    DimConfig dimConfig = verifyDim(dim);
    FacetLabel cp = new FacetLabel(dim, path);
    int dimOrd = taxoReader.getOrdinal(cp);
    if (dimOrd == -1) {
        return null;
    }

    TopOrdAndIntQueue q = new TopOrdAndIntQueue(Math.min(taxoReader.getSize(), topN));

    int bottomValue = 0;

    int ord = children[dimOrd];
    int totValue = 0;
    int childCount = 0;

    TopOrdAndIntQueue.OrdAndValue reuse = null;
    while (ord != TaxonomyReader.INVALID_ORDINAL) {
        if (values[ord] > 0) {
            totValue += values[ord];
            childCount++;
            if (values[ord] > bottomValue) {
                if (reuse == null) {
                    reuse = new TopOrdAndIntQueue.OrdAndValue();
                }
                reuse.ord = ord;
                reuse.value = values[ord];
                reuse = q.insertWithOverflow(reuse);
                if (q.size() == topN) {
                    bottomValue = q.top().value;
                }
            }
        }

        ord = siblings[ord];
    }

    if (totValue == 0) {
        return null;
    }

    if (dimConfig.multiValued) {
        if (dimConfig.requireDimCount) {
            totValue = values[dimOrd];
        } else {
            // Our sum'd value is not correct, in general:
            totValue = -1;
        }
    } else {
        // Our sum'd dim value is accurate, so we keep it
    }

    LabelAndValue[] labelValues = new LabelAndValue[q.size()];
    for (int i = labelValues.length - 1; i >= 0; i--) {
        TopOrdAndIntQueue.OrdAndValue ordAndValue = q.pop();
        FacetLabel child = taxoReader.getPath(ordAndValue.ord);
        labelValues[i] = new LabelAndValue(child.components[cp.length], ordAndValue.value);
    }

    return new FacetResult(dim, path, totValue, labelValues, childCount);
}