Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.params.SolrParams;
import org.apache.solr.common.util.NamedList;
/**
* Models a single field somewhere in a hierarchy of fields as part of a pivot facet.
* This pivot field contains {@link PivotFacetValue}s which may each contain a nested
* {@link PivotFacetField} child. This PivotFacetField may itself
* be a child of a {@link PivotFacetValue} parent.
*
* @see PivotFacetValue
* @see PivotFacetFieldValueCollection
*/
@SuppressWarnings("rawtypes")
public class PivotFacetField {
public final String field;
// null if this is a top level pivot,
// otherwise the value of the parent pivot we are nested under
public final PivotFacetValue parentValue;
public final PivotFacetFieldValueCollection valueCollection;
// Facet parameters relating to this field
private final int facetFieldLimit;
private final int facetFieldMinimumCount;
private final int facetFieldOffset;
private final String facetFieldSort;
private final Map numberOfValuesContributedByShard = new HashMap<>();
private final Map shardLowestCount = new HashMap<>();
private boolean needRefinementAtThisLevel = true;
private PivotFacetField(ResponseBuilder rb, PivotFacetValue parent, String fieldName) {
field = fieldName;
parentValue = parent;
// facet params
SolrParams parameters = rb.req.getParams();
facetFieldMinimumCount = parameters.getFieldInt(field, FacetParams.FACET_PIVOT_MINCOUNT, 1);
facetFieldOffset = parameters.getFieldInt(field, FacetParams.FACET_OFFSET, 0);
facetFieldLimit = parameters.getFieldInt(field, FacetParams.FACET_LIMIT, 100);
String defaultSort = (facetFieldLimit > 0) ? FacetParams.FACET_SORT_COUNT : FacetParams.FACET_SORT_INDEX;
facetFieldSort = parameters.getFieldParam(field, FacetParams.FACET_SORT, defaultSort);
valueCollection = new PivotFacetFieldValueCollection(facetFieldMinimumCount, facetFieldOffset, facetFieldLimit, facetFieldSort);
if ( (facetFieldLimit < 0) ||
// TODO: possible refinement issue if limit=0 & mincount=0 & missing=true
// (ie: we only want the missing count for this field)
(facetFieldLimit <= 0 && facetFieldMinimumCount == 0) ||
(facetFieldSort.equals(FacetParams.FACET_SORT_INDEX) && facetFieldMinimumCount <= 0)
) {
// in any of these cases, there's no need to refine this level of the pivot
needRefinementAtThisLevel = false;
}
}
/**
* A recursive method that walks up the tree of pivot fields/values to build
* a list of String representations of the values that lead down to this
* PivotFacetField.
*
* @return A mutable List of the pivot values leading down to this pivot field,
* will never be null but may contain nulls and may be empty if this is a top
* level pivot field
* @see PivotFacetValue#getValuePath
*/
public List getValuePath() {
if (null != parentValue) {
return parentValue.getValuePath();
}
return new ArrayList(3);
}
/**
* A recursive method to construct a new PivotFacetField object from
* the contents of the {@link NamedList}s provided by the specified shard, relative
* to a parent value (if this is not the top field in the pivot hierarchy)
*
* The associated child {@link PivotFacetValue}s will be recursively built as well.
*
* @see PivotFacetValue#createFromNamedList
* @param shardNumber the id of the shard that provided this data
* @param rb The response builder of the current request
* @param owner the parent value in the current pivot (may be null)
* @param pivotValues the data from the specified shard for this pivot field, may be null or empty
* @return the new PivotFacetField, null if pivotValues is null or empty.
*/
public static PivotFacetField createFromListOfNamedLists(int shardNumber, ResponseBuilder rb, PivotFacetValue owner, List> pivotValues) {
if (null == pivotValues || pivotValues.size() <= 0) return null;
NamedList