예제 #1
0
  /**
   * A recursive method to construct a new <code>PivotFacetField</code> 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)
   *
   * <p>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<NamedList<Object>> pivotValues) {

    if (null == pivotValues || pivotValues.size() <= 0) return null;

    NamedList<Object> firstValue = pivotValues.get(0);
    PivotFacetField createdPivotFacetField =
        new PivotFacetField(rb, owner, PivotFacetHelper.getField(firstValue));

    int lowestCount = Integer.MAX_VALUE;

    for (NamedList<Object> pivotValue : pivotValues) {

      lowestCount = Math.min(lowestCount, PivotFacetHelper.getCount(pivotValue));

      PivotFacetValue newValue =
          PivotFacetValue.createFromNamedList(shardNumber, rb, createdPivotFacetField, pivotValue);
      createdPivotFacetField.valueCollection.add(newValue);
    }

    createdPivotFacetField.shardLowestCount.put(shardNumber, lowestCount);
    createdPivotFacetField.numberOfValuesContributedByShard.put(shardNumber, pivotValues.size());

    return createdPivotFacetField;
  }
예제 #2
0
  /**
   * Merges in the count contributions from the specified shard for each. This method is recursive
   * if the shard data includes sub-pivots
   *
   * @see PivotFacetField#contributeFromShard
   * @see PivotFacetField#createFromListOfNamedLists
   */
  public void mergeContributionFromShard(
      int shardNumber, ResponseBuilder rb, NamedList<Object> value) {
    assert null != value : "can't merge in null data";

    if (!shardHasContributed(shardNumber)) {
      sourceShards.set(shardNumber);
      count += PivotFacetHelper.getCount(value);
      NamedList<NamedList<NamedList<?>>> stats = PivotFacetHelper.getStats(value);
      if (stats != null) {
        statsValues = PivotFacetHelper.mergeStats(statsValues, stats, rb._statsInfo);
      }
      NamedList<Number> shardQueryCounts = PivotFacetHelper.getQueryCounts(value);
      if (shardQueryCounts != null) {
        queryCounts = PivotFacetHelper.mergeQueryCounts(queryCounts, shardQueryCounts);
      }
      SimpleOrderedMap<SimpleOrderedMap<Object>> shardRanges = PivotFacetHelper.getRanges(value);
      if (shardRanges != null) {
        if (rangeCounts == null) {
          rangeCounts = new LinkedHashMap<>(shardRanges.size() / 2);
        }
        RangeFacetRequest.DistribRangeFacet.mergeFacetRangesFromShardResponse(
            rangeCounts, shardRanges);
      }
    }

    List<NamedList<Object>> shardChildPivots = PivotFacetHelper.getPivots(value);
    // sub pivot -- we may not have seen this yet depending on refinement
    if (null == childPivot) {
      childPivot =
          PivotFacetField.createFromListOfNamedLists(shardNumber, rb, this, shardChildPivots);
    } else {
      childPivot.contributeFromShard(shardNumber, rb, shardChildPivots);
    }
  }
예제 #3
0
  private void contributeValueFromShard(
      int shardNumber, ResponseBuilder rb, NamedList<Object> shardValue) {

    incrementShardValueCount(shardNumber);

    Comparable value = PivotFacetHelper.getValue(shardValue);
    int count = PivotFacetHelper.getCount(shardValue);

    // We're changing values so we most mark the collection as dirty
    valueCollection.markDirty();

    if ((!shardLowestCount.containsKey(shardNumber)) || shardLowestCount.get(shardNumber) > count) {
      shardLowestCount.put(shardNumber, count);
    }

    PivotFacetValue facetValue = valueCollection.get(value);
    if (null == facetValue) {
      // never seen before, we need to create it from scratch
      facetValue = PivotFacetValue.createFromNamedList(shardNumber, rb, this, shardValue);
      this.valueCollection.add(facetValue);
    } else {
      facetValue.mergeContributionFromShard(shardNumber, rb, shardValue);
    }
  }