예제 #1
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);
    }
  }
예제 #2
0
  /**
   * A recursive method to construct a new <code>PivotFacetValue</code> object from the contents of
   * the {@link NamedList} provided by the specified shard, relative to the specified field.
   *
   * <p>If the <code>NamedList</code> 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<Object> pivotData) {

    Comparable pivotVal = null;
    int pivotCount = 0;
    List<NamedList<Object>> childPivotData = null;
    NamedList<NamedList<NamedList<?>>> statsValues = null;
    NamedList<Number> queryCounts = null;
    SimpleOrderedMap<SimpleOrderedMap<Object>> ranges = null;

    for (int i = 0; i < pivotData.size(); i++) {
      String key = pivotData.getName(i);
      Object value = pivotData.getVal(i);
      PivotListEntry entry = PivotListEntry.get(key);

      switch (entry) {
        case VALUE:
          pivotVal = (Comparable) value;
          break;
        case FIELD:
          assert parentField.field.equals(value)
              : "Parent Field mismatch: " + parentField.field + "!=" + value;
          break;
        case COUNT:
          pivotCount = (Integer) value;
          break;
        case PIVOT:
          childPivotData = (List<NamedList<Object>>) value;
          break;
        case STATS:
          statsValues = (NamedList<NamedList<NamedList<?>>>) value;
          break;
        case QUERIES:
          queryCounts = (NamedList<Number>) value;
          break;
        case RANGES:
          ranges = (SimpleOrderedMap<SimpleOrderedMap<Object>>) value;
          break;
        default:
          throw new RuntimeException("PivotListEntry contains unaccounted for item: " + entry);
      }
    }

    PivotFacetValue newPivotFacet = new PivotFacetValue(parentField, pivotVal);
    newPivotFacet.count = pivotCount;
    newPivotFacet.sourceShards.set(shardNumber);
    if (statsValues != null) {
      newPivotFacet.statsValues = PivotFacetHelper.mergeStats(null, statsValues, rb._statsInfo);
    }
    if (queryCounts != null) {
      newPivotFacet.queryCounts = PivotFacetHelper.mergeQueryCounts(null, queryCounts);
    }
    if (ranges != null) {
      newPivotFacet.rangeCounts = new LinkedHashMap<>();
      RangeFacetRequest.DistribRangeFacet.mergeFacetRangesFromShardResponse(
          newPivotFacet.rangeCounts, ranges);
    }

    newPivotFacet.childPivot =
        PivotFacetField.createFromListOfNamedLists(shardNumber, rb, newPivotFacet, childPivotData);

    return newPivotFacet;
  }