org.apache.solr.handler.component.PivotFacetValue Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of solr-core Show documentation
Show all versions of solr-core Show documentation
Apache Solr (module: core)
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler.component;
import java.util.BitSet;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.util.PivotListEntry;
/**
* Models a single (value, count) pair that will exist in the collection of values for a
* {@link PivotFacetField} parent. This PivotFacetValue
may itself have a
* nested {@link PivotFacetField} child
*
* @see PivotFacetField
* @see PivotFacetFieldValueCollection
*/
@SuppressWarnings("rawtypes")
public class PivotFacetValue {
private final BitSet sourceShards = new BitSet();
private final PivotFacetField parentPivot;
private final Comparable value;
// child can't be final, circular ref on construction
private PivotFacetField childPivot = null;
private int count; // mutable
private Map statsValues = null;
// named list with objects because depending on how big the counts are we may get either a long or an int
private NamedList queryCounts;
private LinkedHashMap rangeCounts;
private PivotFacetValue(PivotFacetField parent, Comparable val) {
this.parentPivot = parent;
this.value = val;
}
/**
* The value of the asssocated field modeled by this PivotFacetValue
.
* May be null if this PivotFacetValue
models the count for docs
* "missing" the field value.
*
* @see FacetParams#FACET_MISSING
*/
public Comparable getValue() { return value; }
/** The count corrisponding to the value modeled by this PivotFacetValue
*/
public int getCount() { return count; }
/**
* The {@link PivotFacetField} corrisponding to the nested child pivot for this
* PivotFacetValue
. May be null if this object is the leaf of a pivot.
*/
public PivotFacetField getChildPivot() { return childPivot; }
/**
* A recursive method that walks up the tree of pivot fields/values to build
* a list of the String representations of the values that lead down to this
* PivotFacetValue.
*
* @return a mutable List of the pivot value Strings leading down to and including
* this pivot value, will never be null but may contain nulls
* @see PivotFacetField#getValuePath
*/
public List getValuePath() {
List out = parentPivot.getValuePath();
// Note: this code doesn't play nice with custom FieldTypes -- see SOLR-6330
if (null == value) {
out.add(null);
} else if (value instanceof Date) {
out.add(((Date) value).toInstant().toString());
} else {
out.add(value.toString());
}
return out;
}
/**
* A recursive method to construct a new PivotFacetValue
object from
* the contents of the {@link NamedList} provided by the specified shard, relative
* to the specified field.
*
* If the NamedList
contains data for a child {@link PivotFacetField}
* that will be recursively built as well.
*
* @see PivotFacetField#createFromListOfNamedLists
* @param shardNumber the id of the shard that provided this data
* @param rb The response builder of the current request
* @param parentField the parent field in the current pivot associated with this value
* @param pivotData the data from the specified shard for this pivot value
*/
@SuppressWarnings("unchecked")
public static PivotFacetValue createFromNamedList(int shardNumber, ResponseBuilder rb, PivotFacetField parentField, NamedList