protected override QueryProcessResult ApplyQueryRules(QueryValidationInfo info) { return(new QueryProcessResult { IsValid = info.IsValid, UsesPremiumFeatures = !info.ReferencedFields.All(_freeQueryFields.Contains) }); }
public static T SetValidationInfo <T>(this T context, QueryValidationInfo validationInfo) where T : IQueryVisitorContext { if (!(context is IQueryVisitorContextWithValidator validatorContext)) { throw new ArgumentException("Context must be of type IQueryVisitorContextWithAliasResolver", nameof(context)); } validatorContext.ValidationInfo = validationInfo; return(context); }
protected override QueryProcessResult ApplyAggregationRules(QueryValidationInfo info) { if (!info.IsValid) { return new QueryProcessResult { Message = "Invalid aggregation" } } ; if (info.MaxNodeDepth > 6) { return new QueryProcessResult { Message = "Aggregation max depth exceeded" } } ; if (info.Operations.Values.Sum(o => o.Count) > 10) { return new QueryProcessResult { Message = "Aggregation count exceeded" } } ; // Only allow fields that are numeric or have high commonality. if (!info.ReferencedFields.All(_allowedAggregationFields.Contains)) { return new QueryProcessResult { Message = "One or more aggregation fields are not allowed" } } ; // Distinct queries are expensive. if (info.Operations.TryGetValue(AggregationType.Cardinality, out ICollection <string> values) && values.Count > 3) { return new QueryProcessResult { Message = "Cardinality aggregation count exceeded" } } ; // Term queries are expensive. if (info.Operations.TryGetValue(AggregationType.Terms, out values) && (values.Count > 3)) { return new QueryProcessResult { Message = "Terms aggregation count exceeded" } } ; bool usesPremiumFeatures = !info.ReferencedFields.All(_freeAggregationFields.Contains); return(new QueryProcessResult { IsValid = info.IsValid, UsesPremiumFeatures = usesPremiumFeatures }); } } }
protected virtual QueryProcessResult ApplyAggregationRules(QueryValidationInfo info) { return(new QueryProcessResult { IsValid = info.IsValid }); }