public async Task ValidateAsync(object value, ValidationContext context, AddError addError) { if (value is ICollection <Guid> contentIds) { var filter = ClrFilter.In(Path, contentIds.ToList()); var foundIds = await context.GetContentIdsAsync(schemaId, filter); foreach (var id in contentIds) { if (!foundIds.Contains(id)) { addError(context.Path, $"Contains invalid reference '{id}'."); } } } }
public override async ValueTask <FilterNode <ClrValue>?> Visit(CompareFilter <ClrValue> nodeIn, Args args) { if (nodeIn.Value.Value is FilterSphere sphere) { var field = string.Join(".", nodeIn.Path.Skip(1)); var searchQuery = new GeoQuery(args.Schema.Id, field, sphere.Latitude, sphere.Longitude, sphere.Radius, 1000); var searchScope = args.Context.Scope(); var ids = await args.TextIndex.SearchAsync(args.Context.App, searchQuery, searchScope); if (ids == null || ids.Count == 0) { return(ClrFilter.Eq("id", "__notfound__")); } return(ClrFilter.In("id", ids.Select(x => x.ToString()).ToList())); } return(nodeIn); }
private async Task TransformFilterAsync(ClrQuery query, Context context, ISchemaEntity?schema) { if (query.Filter != null && schema != null) { query.Filter = await GeoQueryTransformer.TransformAsync(query.Filter, context, schema, textIndex); } if (!string.IsNullOrWhiteSpace(query.FullText)) { if (schema == null) { throw new InvalidOperationException(); } var textQuery = new TextQuery(query.FullText, 1000) { PreferredSchemaId = schema.Id }; var fullTextIds = await textIndex.SearchAsync(context.App, textQuery, context.Scope()); var fullTextFilter = ClrFilter.Eq("id", "__notfound__"); if (fullTextIds?.Any() == true) { fullTextFilter = ClrFilter.In("id", fullTextIds.Select(x => x.ToString()).ToList()); } if (query.Filter != null) { query.Filter = ClrFilter.And(query.Filter, fullTextFilter); } else { query.Filter = fullTextFilter; } query.FullText = null; } }
public override FilterNode <ClrValue> Visit(InNode nodeIn) { var value = ConstantWithTypeVisitor.Visit(nodeIn.Right); return(ClrFilter.In(PropertyPathVisitor.Visit(nodeIn.Left), value)); }