public async Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { var childQuery = ctx.Source.GetChildQuery(); if (childQuery == null) { return; } var childContext = new QueryBuilderContext <T>(childQuery.Query, ctx.Options, null, ctx, ContextType.Child); await _queryBuilder.BuildAsync(childContext).AnyContext(); if ((childContext.Query == null || ((IQueryContainer)childContext.Query).IsConditionless) && (childContext.Filter == null || ((IQueryContainer)childContext.Filter).IsConditionless)) { return; } ctx.Filter &= new HasChildQuery { Type = childQuery.Type, Query = new BoolQuery { Must = new QueryContainer[] { childContext.Query }, Filter = new QueryContainer[] { childContext.Filter }, } }; }
public async Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { var childQuery = ctx.GetSourceAs <IChildQuery>(); if (childQuery?.ChildQuery == null) { return; } if (String.IsNullOrEmpty(childQuery.ChildQuery.Type)) { throw new ArgumentException("Must specify a child type for child queries."); } // this should pass an options object that is for the child index type var childContext = new QueryBuilderContext <T>(childQuery.ChildQuery, ctx.Options, null, ctx, ContextType.Child); await _queryBuilder.BuildAsync(childContext).AnyContext(); if ((childContext.Query == null || childContext.Query.IsConditionless) && (childContext.Filter == null || childContext.Filter.IsConditionless)) { return; } ctx.Filter &= new HasChildFilter { Query = childContext.Query, Filter = childContext.Filter, Type = childQuery.ChildQuery.Type }; }
public async Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { var parentQuery = ctx.GetSourceAs <IParentQuery>(); bool hasIds = ctx.GetSourceAs <IIdentityQuery>()?.Ids.Count > 0; if (parentQuery == null) { return; } var options = ctx.GetOptionsAs <IElasticQueryOptions>(); IQueryOptions parentOptions = null; if (options != null && options.HasParent == false) { return; } if (options != null && options.ParentSupportsSoftDeletes && hasIds == false) { if (parentQuery.ParentQuery == null) { parentQuery.ParentQuery = new ParentQuery(); } var parentType = options.ChildType.GetParentIndexType(); if (parentType == null) { throw new ApplicationException("ParentIndexTypeName on child index type must match the name of the parent type."); } parentOptions = new ElasticQueryOptions(parentType); } if (parentQuery.ParentQuery == null) { return; } var parentContext = new QueryBuilderContext <object>(parentQuery.ParentQuery, parentOptions, null, ctx, ContextType.Parent); await _queryBuilder.BuildAsync(parentContext).AnyContext(); if ((parentContext.Query == null || parentContext.Query.IsConditionless) && (parentContext.Filter == null || parentContext.Filter.IsConditionless)) { return; } ctx.Filter &= new HasParentFilter { Query = parentContext.Query, Filter = parentContext.Filter, Type = options?.ChildType?.GetParentIndexType().Name }; }
public async Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { var options = ctx.Options.GetElasticTypeSettings(); if (options.HasParent == false) { return; } var parentQuery = ctx.Source.GetParentQuery(); bool hasIds = ctx.Source.GetIds().Count > 0; // even if no parent query has been set, run it through to get soft delete filter if (options.ParentSupportsSoftDeletes && hasIds == false && parentQuery == null) { parentQuery = new RepositoryQuery(); } if (parentQuery == null) { return; } var parentType = options.ChildType.GetParentIndexType(); if (parentType == null) { throw new ApplicationException("ParentIndexTypeName on child index type must match the name of the parent type."); } var parentOptions = new CommandOptions().ElasticType(parentType); var parentContext = new QueryBuilderContext <object>(parentQuery, parentOptions, null, ctx, ContextType.Parent); await _queryBuilder.BuildAsync(parentContext).AnyContext(); if ((parentContext.Query == null || ((IQueryContainer)parentContext.Query).IsConditionless) && (parentContext.Filter == null || ((IQueryContainer)parentContext.Filter).IsConditionless)) { return; } ctx.Filter &= new HasParentQuery { Type = parentType.Name, Query = new BoolQuery { Must = new QueryContainer[] { parentContext.Query }, Filter = new QueryContainer[] { parentContext.Filter }, } }; }
public async Task BuildAsync <T>(QueryBuilderContext <T> ctx) where T : class, new() { if (ctx.Type == ContextType.SystemFilter) { return; } var systemFilter = ctx.GetSourceAs <ISystemFilterQuery>(); if (systemFilter == null) { return; } var innerContext = new QueryBuilderContext <T>(systemFilter.SystemFilter, ctx.Options, ctx.Search, ctx, ContextType.SystemFilter) { Filter = ctx.Filter, Query = ctx.Query }; await _queryBuilder.BuildAsync <T>(innerContext).AnyContext(); ctx.Filter = innerContext.Filter; ctx.Query = innerContext.Query; }