コード例 #1
0
ファイル: FilterVisitor.cs プロジェクト: jrlost/squidex
        public override FilterDefinition <T> Visit(CompareFilter <ClrValue> nodeIn, None args)
        {
            var propertyName = nodeIn.Path.ToString();

            var value = nodeIn.Value.Value;

            switch (nodeIn.Operator)
            {
            case CompareOperator.Empty:
                return(Filter.Or(
                           Filter.Exists(propertyName, false),
                           Filter.Eq <object?>(propertyName, null),
                           Filter.Eq <object?>(propertyName, string.Empty),
                           Filter.Size(propertyName, 0)));

            case CompareOperator.Exists:
                return(Filter.And(
                           Filter.Exists(propertyName, true),
                           Filter.Ne <object?>(propertyName, null)));

            case CompareOperator.Matchs:
                return(Filter.Regex(propertyName, BuildMatchRegex(nodeIn)));

            case CompareOperator.StartsWith:
                return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => "^" + s)));

            case CompareOperator.Contains:
                return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => s)));

            case CompareOperator.EndsWith:
                return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => s + "$")));

            case CompareOperator.Equals:
                return(Filter.Eq(propertyName, value));

            case CompareOperator.GreaterThan:
                return(Filter.Gt(propertyName, value));

            case CompareOperator.GreaterThanOrEqual:
                return(Filter.Gte(propertyName, value));

            case CompareOperator.LessThan:
                return(Filter.Lt(propertyName, value));

            case CompareOperator.LessThanOrEqual:
                return(Filter.Lte(propertyName, value));

            case CompareOperator.NotEquals:
                return(Filter.Ne(propertyName, value));

            case CompareOperator.In:
                return(Filter.In(propertyName, ((IList)value !).OfType <object>()));
            }

            throw new NotSupportedException();
        }
コード例 #2
0
        public PagedList <dynamic> GetSharedNodes(Guid userId, int pageNumber = 1, int pageSize = 20, bool isPublicOnly = false)
        {
            var filter = _filterBase & _builder.Eq("OwnedBy", userId) & _builder.Or(
                _builder.Eq("AccessPermissions.IsPublic", true),
                _builder.Not(_builder.Size("AccessPermissions.Users", 0)),
                _builder.Not(_builder.Size("AccessPermissions.Groups", 0))
                );

            if (isPublicOnly)
            {
                filter = filter & _builder.Eq("AccessPermissions.IsPublic", true);
            }

            var nodes = _nodes.Aggregate()
                        .Lookup <BsonDocument, BsonDocument>(nameof(AccessPermissions), "_id", "_id", nameof(AccessPermissions))
                        .Unwind <dynamic>(nameof(AccessPermissions))
                        .Match(filter.Render(_nodes.DocumentSerializer, _nodes.Settings.SerializerRegistry));

            return(PagedList(nodes, pageNumber, pageSize));
        }
コード例 #3
0
 public object SizeEq(string arrayProperty, int value)
 {
     return(InternalBuilder.Size(arrayProperty, value));
 }
コード例 #4
0
ファイル: Query.cs プロジェクト: zluckymn/NetCoreMachineLearn
 //
 // 摘要:
 //     Tests that the size of the named array is equal to some value (see $size).
 //
 // 参数:
 //   name:
 //     The name of the element to test.
 //
 //   size:
 //     The size to compare to.
 //
 // 返回结果:
 //     The builder (so method calls can be chained).
 public static FilterDefinition <BsonDocument> Size(string name, int size)
 {
     return(filter.Size(name, size));
 }