public static FilterDefinition <MongoContentEntity> ToFilter(this Query query, Guid schemaId, Status[] status) { var filters = new List <FilterDefinition <MongoContentEntity> > { Filter.Eq(x => x.IndexedSchemaId, schemaId), Filter.Ne(x => x.IsDeleted, true) }; if (status != null) { filters.Add(Filter.In(x => x.Status, status)); } var filter = query.BuildFilter <MongoContentEntity>(); if (filter.Filter != null) { if (filter.Last) { filters.Add(filter.Filter); } else { filters.Insert(0, filter.Filter); } } return(Filter.And(filters)); }
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(); }
private FilterDefinition <ToDoListEntity> ApplyWhereStatement(FilterDefinitionBuilder <ToDoListEntity> builder, ListQueryDataStructure queryDataStructure) { FilterDefinition <ToDoListEntity> filter = builder.Ne(x => x.Status, (int)ToDoListStatus.Archived); if (queryDataStructure.Id.HasValue) { filter = filter & (builder.Eq(x => x.Id, queryDataStructure.Id.Value)); } if (queryDataStructure.UserId.HasValue) { filter = filter & (builder.Eq(x => x.UserId, queryDataStructure.UserId.Value)); } if (!string.IsNullOrWhiteSpace(queryDataStructure.Name)) { filter = filter & (builder.Regex(x => x.Name, queryDataStructure.Name)); } if (queryDataStructure.Statuses != null && queryDataStructure.Statuses.Any()) { filter = filter & (builder.In(x => x.Status, queryDataStructure.Statuses)); } return(filter); }
private FilterDefinition <TDocument> AddGetFilter <TDocument>() where TDocument : IBaseModel { var compositeFilter = new FilterDefinitionBuilder <TDocument>(); var videoFilterDef = compositeFilter.Empty; videoFilterDef = videoFilterDef & compositeFilter.Ne(x => x.IsDeleted, true); return(videoFilterDef); }
public override FilterDefinition <T> VisitStringOp([NotNull] FilterParser.StringOpContext context) { string id = context.ID().GetText(); string str = (context.STRING() ?? context.EMPTY()).GetText().Trim('\''); var op = context.op.Type; switch (op) { case FilterParser.EQ: return(_builder.Eq(id, str)); case FilterParser.NE: return(_builder.Ne(id, str)); default: throw new InvalidOperationException($"Invalid StringOp {context.GetText()}"); } }
public static FilterDefinition <BsonDocument> GetCustomerFilter() { var filterBuilder = new FilterDefinitionBuilder <BsonDocument>(); var managerFilter = filterBuilder.Eq("ManagerNr", "100670"); var monthFilter = filterBuilder.In("Month", new[] { 10, 12 }); var minDateFilter = filterBuilder.Ne("DateOfBirth", DateTime.MinValue); var filter = managerFilter & monthFilter & minDateFilter; return(filter); }
private static FilterDefinition <MongoContentEntity> CreateFilter(Guid?appId, Guid?schemaId, ICollection <Guid> ids, Status[] status, ClrQuery query) { var filters = new List <FilterDefinition <MongoContentEntity> >(); if (appId.HasValue) { filters.Add(Filter.Eq(x => x.IndexedAppId, appId.Value)); } if (schemaId.HasValue) { filters.Add(Filter.Eq(x => x.IndexedSchemaId, schemaId.Value)); } filters.Add(Filter.Ne(x => x.IsDeleted, true)); if (status != null) { filters.Add(Filter.In(x => x.Status, status)); } if (ids != null && ids.Count > 0) { if (ids.Count > 1) { filters.Add(Filter.In(x => x.Id, ids)); } else { filters.Add(Filter.Eq(x => x.Id, ids.First())); } } if (query?.Filter != null) { filters.Add(query.Filter.BuildFilter <MongoContentEntity>()); } return(Filter.And(filters)); }
public FilterDefinition <IUser> ConcatenateFilter(List <SearchFilter> filters, FilterDefinitionBuilder <IUser> builder, FilterDefinition <IUser> filter, int i) { if (filters[i] is SearchFilter) { switch (filters[i].FieldName) { case "_id": filter = filter & builder.Ne("_id", ((ValueSearchFilter <string>)filters[i]).Value); break; case "UserType": filter = filter & builder.Eq(filters[i].FieldName, ((ValueSearchFilter <string>)filters[i]).Value); break; case "Gender": if (((ValueSearchFilter <int>)filters[i]).Value != 2) { filter = filter & builder.Eq(filters[i].FieldName, ((ValueSearchFilter <int>)filters[i]).Value); } break; case "Location": break; case "Expertise": //ExpertiseEntityService expertiseService = new ExpertiseEntityService(); //IExpertise expertiseVal = await expertiseService.GetExpertiseById(((ValueSearchFilter<string>)filters[i]).Value); //expertiseVal.ExpertiseName filter = filter & builder.Eq(filters[i].FieldName, ((ValueSearchFilter <string>)filters[i]).Value); break; case "Reputation": filter = filter & builder.Eq(filters[i].FieldName, ((ValueSearchFilter <int>)filters[i]).Value); break; case "Showers": filter = filter & builder.Eq(filters[i].FieldName, ((ValueSearchFilter <bool>)filters[i]).Value); break; case "ParkingLot": filter = filter & builder.Eq(filters[i].FieldName, ((ValueSearchFilter <bool>)filters[i]).Value); break; } } else { filter = filter & builder.Lte(filters[i].FieldName, ((RangeSearchFilter)filters[i]).ToValue) & builder.Gt(filters[i].FieldName, ((RangeSearchFilter)filters[i]).FromValue); } return(filter); }
public static FilterDefinition <BsonDocument> GetApacheRequests(IMongoCollection <BsonDocument> collection, bool includeGatewayHealthCheckRequests = false) { // Filter down to only access files. FilterDefinition <BsonDocument> query = Query.Regex("file", new BsonRegularExpression("^access.*")); // Gateway health check requests are generally noise, but may be desired in some situations. if (!includeGatewayHealthCheckRequests) { query = Query.And(query, Query.Ne("resource", "/favicon.ico")); } return(query); }
public Puzzle GetOneRandomly(List <int> excludedIds, string variant, int?userId, double nearRating = 1500) { FilterDefinitionBuilder <Puzzle> filterBuilder = Builders <Puzzle> .Filter; FilterDefinition <Puzzle> filter = filterBuilder.Nin("_id", excludedIds) & filterBuilder.Eq("inReview", false) & filterBuilder.Eq("approved", true); if (variant != "Mixed") { filter &= filterBuilder.Eq("variant", variant); } if (userId.HasValue) { filter &= filterBuilder.Ne("author", userId.Value) & filterBuilder.Nin("reviewers", new int[] { userId.Value }); } FilterDefinition <Puzzle> lteFilter = filter; FilterDefinition <Puzzle> gtFilter = filter; bool higherRated = RandomBoolean(); gtFilter &= filterBuilder.Gt("rating.value", nearRating); lteFilter &= filterBuilder.Lte("rating.value", nearRating); var foundGt = puzzleCollection.Find(gtFilter); var foundLte = puzzleCollection.Find(lteFilter); if (foundGt == null && foundLte == null) { return(null); } SortDefinitionBuilder <Puzzle> sortBuilder = Builders <Puzzle> .Sort; foundGt = foundGt.Sort(sortBuilder.Ascending("rating.value")).Limit(1); foundLte = foundLte.Sort(sortBuilder.Descending("rating.value")).Limit(1); Puzzle oneGt = foundGt.FirstOrDefault(); Puzzle oneLte = foundLte.FirstOrDefault(); if (oneGt == null) { return(oneLte); } else if (oneLte == null) { return(oneGt); } else { return(RandomBoolean() ? oneGt : oneLte); } }
public static string GetBootstrapRequestIdForSession(string sessionId, IMongoCollection <BsonDocument> collection) { try { var bootstrapRequestQuery = Query.And(Query.Eq("sess", sessionId), Query.Eq("k", "lock-session"), Query.Ne("v.workbook", "Book1")); BsonDocument bootstrapRequestEvent = collection.Find(bootstrapRequestQuery).Sort(Builders <BsonDocument> .Sort.Ascending("ts")).Limit(1).First(); return(BsonDocumentHelper.GetString("req", bootstrapRequestEvent)); } catch { return(null); } }
public override FilterDefinition <T> Visit(FilterComparison nodeIn) { var propertyName = string.Join(".", nodeIn.Lhs); switch (nodeIn.Operator) { case FilterOperator.Empty: return(Filter.Or(Filter.Exists(propertyName, false), Filter.Eq(propertyName, default(T)), Filter.Eq(propertyName, string.Empty), Filter.Eq(propertyName, new T[0]))); case FilterOperator.StartsWith: return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => "^" + s))); case FilterOperator.Contains: return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => s))); case FilterOperator.EndsWith: return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => s + "$"))); case FilterOperator.Equals: return(Filter.Eq(propertyName, nodeIn.Rhs.Value)); case FilterOperator.GreaterThan: return(Filter.Gt(propertyName, nodeIn.Rhs.Value)); case FilterOperator.GreaterThanOrEqual: return(Filter.Gte(propertyName, nodeIn.Rhs.Value)); case FilterOperator.LessThan: return(Filter.Lt(propertyName, nodeIn.Rhs.Value)); case FilterOperator.LessThanOrEqual: return(Filter.Lte(propertyName, nodeIn.Rhs.Value)); case FilterOperator.NotEquals: return(Filter.Ne(propertyName, nodeIn.Rhs.Value)); case FilterOperator.In: return(Filter.In(propertyName, ((IList)nodeIn.Rhs.Value).OfType <object>())); } throw new NotSupportedException(); }
public FilterDefinition <T> GetFromCompareType <T>(FilterCondition s) { FilterDefinitionBuilder <T> filter = Builders <T> .Filter; if (s.Value == null) { return(filter.Empty); } switch (s.CompareType) { case TableCompareType.EQ: return(filter.Eq(s.Key, s.Value)); case TableCompareType.GT: return(filter.Gt(s.Key, s.Value)); case TableCompareType.GTE: return(filter.Gte(s.Key, s.Value)); case TableCompareType.LT: return(filter.Lt(s.Key, s.Value)); case TableCompareType.LTE: return(filter.Lte(s.Key, s.Value)); case TableCompareType.NE: return(filter.Ne(s.Key, s.Value)); case TableCompareType.REGEX: { return(filter.Regex(s.Key, s.Value.ToString())); } case TableCompareType.TEXT: return(filter.Text(s.Value.ToString())); default: return(filter.Eq(s.Key, s.Value)); } }
public override FilterDefinition <MongoContentEntity> Visit(BinaryOperatorNode nodeIn) { if (nodeIn.OperatorKind == BinaryOperatorKind.And) { return(Filter.And(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.OperatorKind == BinaryOperatorKind.Or) { return(Filter.Or(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual) { return(Filter.Ne(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.Equal) { return(Filter.Eq(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan) { return(Filter.Lt(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual) { return(Filter.Lte(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan) { return(Filter.Gt(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual) { return(Filter.Gte(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } throw new NotSupportedException(); }
public static FilterDefinition <MongoContentEntity> BuildQuery(ODataUriParser query, Guid schemaId, Status[] status, ConvertProperty propertyCalculator) { var filters = new List <FilterDefinition <MongoContentEntity> > { Filter.Eq(x => x.IndexedSchemaId, schemaId), }; if (status != null) { filters.Add(Filter.Ne(x => x.IsDeleted, true)); filters.Add(Filter.In(x => x.Status, status)); } var filter = query.BuildFilter <MongoContentEntity>(propertyCalculator); if (filter.Filter != null) { if (filter.Last) { filters.Add(filter.Filter); } else { filters.Insert(0, filter.Filter); } } if (filters.Count == 1) { return(filters[0]); } else { return(Filter.And(filters)); } }
// // 摘要: // Tests that the value of the named element is not equal to some value (see $ne). // // 参数: // name: // The name of the element to test. // // value: // The value to compare to. // // 返回结果: // The builder (so method calls can be chained). public static FilterDefinition <BsonDocument> NE(string name, BsonValue value) { return(filter.Ne(name, value)); }
public object NotEq <TProperty>(string property, TProperty value) { return(InternalBuilder.Ne(property, value)); }
public override FilterDefinition <MongoContentEntity> Visit(BinaryOperatorNode nodeIn) { if (nodeIn.OperatorKind == BinaryOperatorKind.And) { return(Filter.And(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.OperatorKind == BinaryOperatorKind.Or) { return(Filter.Or(nodeIn.Left.Accept(this), nodeIn.Right.Accept(this))); } if (nodeIn.Left is SingleValueFunctionCallNode functionNode) { var regexFilter = Visit(functionNode); var value = BuildValue(nodeIn.Right); if (value is bool booleanRight) { if ((nodeIn.OperatorKind == BinaryOperatorKind.Equal && !booleanRight) || (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual && booleanRight)) { regexFilter = Filter.Not(regexFilter); } return(regexFilter); } } else { if (nodeIn.OperatorKind == BinaryOperatorKind.NotEqual) { var field = BuildFieldDefinition(nodeIn.Left); return(Filter.Or( Filter.Not(Filter.Exists(field)), Filter.Ne(field, BuildValue(nodeIn.Right)))); } if (nodeIn.OperatorKind == BinaryOperatorKind.Equal) { return(Filter.Eq(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThan) { return(Filter.Lt(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.LessThanOrEqual) { return(Filter.Lte(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThan) { return(Filter.Gt(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } if (nodeIn.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual) { return(Filter.Gte(BuildFieldDefinition(nodeIn.Left), BuildValue(nodeIn.Right))); } } throw new NotSupportedException(); }
public void Ne_with_field_name_should_render_correctly(int?value, string expectedFilter) { var filter = __subject.Ne("I", value); filter.Render(__serializer, __registry).Should().Be(expectedFilter); }
public void Ne_with_field_name_should_render_correctly(IEnumerable <int> values, string expectedFilter) { var filter = __subject.Ne("A", values); filter.Render(__serializer, __registry).Should().Be(expectedFilter); }
public List <Record> GetAll() { var result = records.Find(filterBuilder.Ne(record => record.id, null)); return(result.ToList()); }
public List <User> GetAll() { var result = users.Find(filterBuilder.Ne(user => user.id, null)); return(result.ToList()); }