Example usage for org.apache.lucene.facet FacetResult FacetResult

List of usage examples for org.apache.lucene.facet FacetResult FacetResult

Introduction

In this page you can find the example usage for org.apache.lucene.facet FacetResult FacetResult.

Prototype

public FacetResult(String dim, String[] path, Number value, LabelAndValue[] labelValues, int childCount) 

Source Link

Document

Sole constructor.

Usage

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.util.FilteredSortedSetDocValuesFacetCounts.java

License:Apache License

@Override
public FacetResult getTopChildren(int topN, String dim, String... path) throws IOException {
    FacetResult topChildren = super.getTopChildren(topN, dim, path);

    LabelAndValue[] labelAndValues = topChildren.labelValues;

    for (ScoreDoc scoreDoc : docs.scoreDocs) {
        labelAndValues = filterFacet(scoreDoc.doc, dim, labelAndValues);
    }//w ww  . ja  va  2  s.c  om

    int childCount = labelAndValues.length;
    Number value = 0;
    for (LabelAndValue lv : labelAndValues) {
        value = value.longValue() + lv.value.longValue();
    }

    return new FacetResult(dim, path, value, labelAndValues, childCount);
}

From source file:org.fao.geonet.kernel.search.facet.ItemBuilder.java

License:Open Source License

private FacetResult getTopChildren(String... path) {
    try {/* w ww.j a v  a 2s  .c  o m*/
        if (config.getDimension().isLocalized() && !config.getDimension().getLocales().contains(langCode)) {
            return new FacetResult(config.getDimension().getName(langCode), path, 0, new LabelAndValue[0], 0);
        } else {
            return facets.getTopChildren(config.getMax(), config.getDimension().getName(langCode), path);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.fao.geonet.kernel.search.facet.ItemBuilderTest.java

License:Open Source License

private FacetResult buildFacetResult(int count, String[] path, LabelAndValue... labelAndValues) {
    return new FacetResult(DIMENSION_NAME, path, new Integer(count), labelAndValues, labelAndValues.length);
}

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.  ja va 2s .  c o  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);
}