Exemplo n.º 1
0
        /// <summary>
        /// Aggregate resuts over a clause
        /// </summary>
        /// <param name="groupField">Field that will be used as term to group aggregation results</param>
        /// <param name="field">Id field uppon the aggregation will be used</param>
        /// <param name="aggType">Type of Aggregation</param>
        public FindRequest <T> TermAggregation(Expression <Func <T, object> > groupField, Expression <Func <T, object> > field, EnAggregationType aggType)
        {
            //Get term
            var termName          = Utils.ExpressionAttributeName(groupField);
            TermsAggregation term = null;

            if (!searchInfo.termDictionary.ContainsKey(termName))
            {
                term = new TermsAggregation(termName)
                {
                    Field = groupField
                };
                searchInfo.termDictionary.Add(termName, term);
            }
            else
            {
                term = searchInfo.termDictionary[termName];
            }

            if (term != null)
            {
                //if(agg)
                AggregationContainer aggr = null;
                string pKey = "";
                switch (aggType)
                {
                case EnAggregationType.Sum:
                    pKey = string.Format("{0}_sum", termName);
                    aggr = new SumAggregation(pKey, field);
                    break;

                case EnAggregationType.Average:
                    pKey = string.Format("{0}_avg", termName);
                    aggr = new AverageAggregation(pKey, field);
                    break;

                case EnAggregationType.Min:
                    pKey = string.Format("{0}_min", termName);
                    aggr = new MinAggregation(pKey, field);
                    break;

                case EnAggregationType.Max:
                    pKey = string.Format("{0}_max", termName);
                    aggr = new MaxAggregation(pKey, field);
                    break;
                }
                if (aggr != null)
                {
                    if (term.Aggregations == null)
                    {
                        term.Aggregations = new AggregationDictionary();
                    }
                    term.Aggregations.Add(pKey, aggr);
                }
            }
            return(this);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Aggregate resuts
        /// </summary>
        /// <param name="key">Key identifier of results</param>
        /// <param name="field">Id field uppon the aggregation will be used</param>
        /// <param name="aggType">Type of Aggregation</param>
        public FindRequest <T> Aggregation(string key, Expression <Func <T, object> > field, EnAggregationType aggType)
        {
            AggregationContainer aggr = null;

            switch (aggType)
            {
            case EnAggregationType.Sum:
                aggr = new SumAggregation(key, field);
                break;

            case EnAggregationType.Average:
                aggr = new AverageAggregation(key, field);
                break;

            case EnAggregationType.Min:
                aggr = new MinAggregation(key, field);
                break;

            case EnAggregationType.Max:
                aggr = new MaxAggregation(key, field);
                break;
            }
            if (aggr != null)
            {
                searchInfo.Aggregations.Add(key, aggr);
            }
            return(this);
        }