Example usage for org.apache.lucene.facet FacetsConfig pathToString

List of usage examples for org.apache.lucene.facet FacetsConfig pathToString

Introduction

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

Prototype

public static String pathToString(String[] path, int length) 

Source Link

Document

Turns the first length elements of path into an encoded string.

Usage

From source file:com.qwazr.search.query.DrillDrownQuery.java

License:Apache License

final static Term facetTerm(String indexedField, String dim, String... path) {
    return new Term(indexedField, FacetsConfig.pathToString(dim, path));
}

From source file:com.qwazr.search.query.FacetPathQuery.java

License:Apache License

@Override
final public Query getQuery(QueryContext queryContext) throws IOException {
    Objects.requireNonNull(dimension, "The dimension is missing");
    final String indexFieldName = queryContext.analyzer.getContext().facetsConfig
            .getDimConfig(dimension).indexFieldName;
    final Term term = new Term(indexFieldName, FacetsConfig.pathToString(dimension, path));
    return new org.apache.lucene.search.TermQuery(term);
}

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

License:Apache License

private LabelAndValue[] filterFacet(int docId, String dimension, LabelAndValue[] labelAndValues)
        throws IOException {
    boolean filterd = false;
    Map<String, Long> newValues = new HashMap<String, Long>();

    Document document = reader.document(docId);
    SortedSetDocValues docValues = state.getDocValues();
    docValues.setDocument(docId);/* w w  w  .  j  a  v  a  2s  .  c  o  m*/

    // filter using doc values (avoiding requiring stored values)
    if (!filter.isAccessible(document.getField(FieldNames.PATH).stringValue() + "/" + dimension)) {
        filterd = true;
        for (LabelAndValue lv : labelAndValues) {
            long existingCount = lv.value.longValue();

            BytesRef key = new BytesRef(FacetsConfig.pathToString(dimension, new String[] { lv.label }));
            long l = docValues.lookupTerm(key);
            if (l >= 0) {
                if (existingCount > 0) {
                    newValues.put(lv.label, existingCount - 1);
                } else {
                    if (newValues.containsKey(lv.label)) {
                        newValues.remove(lv.label);
                    }
                }
            }
        }
    }
    LabelAndValue[] filteredLVs;
    if (filterd) {
        filteredLVs = new LabelAndValue[newValues.size()];
        int i = 0;
        for (Map.Entry<String, Long> entry : newValues.entrySet()) {
            filteredLVs[i] = new LabelAndValue(entry.getKey(), entry.getValue());
            i++;
        }
    } else {
        filteredLVs = labelAndValues;
    }

    return filteredLVs;
}