Ejemplo n.º 1
0
        private TermsAggregationDescriptor <PersistentEvent> BuildTermSort(TermsAggregationDescriptor <PersistentEvent> aggregations, IEnumerable <FieldAggregation> fields)
        {
            var field = fields.FirstOrDefault(f => f.SortOrder.HasValue);

            if (field?.SortOrder == null)
            {
                return(aggregations);
            }

            return(field.SortOrder.Value == Foundatio.Repositories.Models.SortOrder.Ascending ? aggregations.OrderAscending(field.Key) : aggregations.OrderDescending(field.Key));
        }
		public void TermAggregationSerializes()
		{
			var s = new TermsAggregationDescriptor<ElasticsearchProject>()
				.CollectMode(TermsAggregationCollectMode.BreadthFirst)
				.ExecutionHint(TermsAggregationExecutionHint.GlobalOrdinalsLowCardinality)
				.Field(p => p.Country)
				.MinimumDocumentCount(1)
				.OrderAscending("_count");

			this.JsonEquals(s, MethodBase.GetCurrentMethod());
		}
Ejemplo n.º 3
0
        public void TermAggregationSerializes()
        {
            var s = new TermsAggregationDescriptor <ElasticsearchProject>()
                    .CollectMode(TermsAggregationCollectMode.BreadthFirst)
                    .ExecutionHint(TermsAggregationExecutionHint.GlobalOrdinalsLowCardinality)
                    .Field(p => p.Country)
                    .MinimumDocumentCount(1)
                    .OrderAscending("_count");

            this.JsonEquals(s, MethodBase.GetCurrentMethod());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a nested aggregation. Wraps the aggregation on which it is called by a new Terms aggregation, using the provided fieldName.
        /// </summary>
        public static AggregationContainerDescriptor <T> GroupBy <T>(this AggregationContainerDescriptor <T> innerAggregation, string fieldName) where T : class
        {
            var v = new AggregationContainerDescriptor <T>();

            v.Terms(fieldName, tr =>
            {
                var trmAggDescriptor = new TermsAggregationDescriptor <T>();
                trmAggDescriptor.Field(fieldName);
                trmAggDescriptor.Size(int.MaxValue);
                return(trmAggDescriptor.Aggregations(x => innerAggregation));
            });

            return(v);
        }
Ejemplo n.º 5
0
        public static AggregationDescriptor <T> GroupBy <T>(this AggregationDescriptor <T> innerAggregation, String key) where T : class
        {
            AggregationDescriptor <T> v = new AggregationDescriptor <T>();

            v.Terms(key, tr =>
            {
                TermsAggregationDescriptor <T> trmAggDescriptor = new TermsAggregationDescriptor <T>();
                trmAggDescriptor.Field(key);
                trmAggDescriptor.Size(int.MaxValue);
                return(trmAggDescriptor.Aggregations(x => innerAggregation));
            });

            return(v);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a nested aggregation. Wraps the aggregation on which it is called by a new Terms aggregation, using the provided fieldGetter function to terms on the field.
        /// </summary>
        public static AggregationContainerDescriptor <T> GroupBy <T>(this AggregationContainerDescriptor <T> innerAggregation, Expression <Func <T, object> > fieldGetter) where T : class
        {
            var fieldName = fieldGetter.GetAggName(AggType.GroupBy);
            var v         = new AggregationContainerDescriptor <T>();

            v.Terms(fieldName, tr =>
            {
                var trmAggDescriptor = new TermsAggregationDescriptor <T>();
                trmAggDescriptor.Field(fieldGetter);
                trmAggDescriptor.Size(int.MaxValue);
                return(trmAggDescriptor.Aggregations(x => innerAggregation));
            });

            return(v);
        }
Ejemplo n.º 7
0
 private TermsAggregationDescriptor<PersistentEvent> BuildTermSort(TermsAggregationDescriptor<PersistentEvent> aggregations, IEnumerable<FieldAggregation> fields) {
     var field = fields.FirstOrDefault(f => f.SortOrder.HasValue);
     if (field?.SortOrder == null)
         return aggregations;
     
     return field.SortOrder.Value == Foundatio.Repositories.Models.SortOrder.Ascending ? aggregations.OrderAscending(field.Key) : aggregations.OrderDescending(field.Key);
 }