/// <summary> /// terms_stats and terms facet responses have each field in an independent object with all /// possible operations for that field. Multiple fields means multiple objects /// each of which might not have all possible terms. Convert that structure into /// an SQL-style row with one term per row containing each aggregate field and operation combination. /// </summary> /// <param name="termsStats">Facets of type terms or terms_stats.</param> /// <returns>An <see cref="IEnumerable{AggregateRow}"/> containing keys and fields representing /// the terms and statistics.</returns> internal IEnumerable <AggregateTermRow> FlattenTermsToAggregateRows(IEnumerable <JToken> termsStats) { return(termsStats .SelectMany(t => t["terms"]) .GroupBy(t => t["term"]) .Select(g => new AggregateTermRow(AggregateRow.ParseValue(g.Key, groupKeyType), g.SelectMany(CreateAggregateFields)))); }
internal static object GetKey(AggregateRow row) { if (row is AggregateTermRow) { return(((AggregateTermRow)row).Key); } if (row is AggregateStatisticalRow) { return(((AggregateStatisticalRow)row).Key); } return(null); }
internal static object GetValue(AggregateRow row, string name, string operation, Type valueType) { return(row.GetValue(name, operation, valueType)); }