/// <summary> /// Get Contents By Segment /// </summary> /// <param name="segmentedCode"></param> /// <returns></returns> public async Task <IEnumerable <ArticleContent> > GetContentsBySegment(IEnumerable <Segmentation> segments, BusinessRule businessRule, IEnumerable <string> exclude = null) { //Todo get all segmentCodes var segmentedCodes = segments.Select(x => x.SegmentedCode).ToList(); var contentSegments = await _repository.GetAllAsync <SegmentedContent>(x => x.SegmentedCode.Equals(segmentedCodes[0])); var contentIds = contentSegments.Select(x => x.ContentId); var filterDefinition = new FilterDefinitionBuilder <ArticleContent>(); var filter = filterDefinition.In(x => x.ContentId, contentIds); if (businessRule != null) { filter = filter & filterDefinition.Eq(x => x.ContentType, businessRule.ContentType); } if (exclude != null) { filter = filter & filterDefinition.Nin(x => x.ContentId, exclude); } return(await _repository.FindAsync <ArticleContent>(filter, orderBy : x => x.OrderByDescending(d => d.Title))); }
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 VizqlSession AppendEtcEventsForSession(VizqlSession session, IMongoCollection <BsonDocument> collection) { var filter = Query.Nin("k", VizqlEventClassesByKeytype.Keys); var unsupportedKeyTypes = collection.Distinct <string>("k", filter).ToEnumerable(); foreach (var keyType in unsupportedKeyTypes) { IEnumerable <BsonDocument> documents; if (session is VizqlServerSession) { documents = GetEventsForKeyBySession(session.VizqlSessionId, keyType, collection); } else if (session is VizqlDesktopSession) { VizqlDesktopSession desktopSession = session as VizqlDesktopSession; documents = GetEventsForKeyByPid(desktopSession.ProcessId, keyType, collection); } else { throw new Exception("VizqlSession must be of type Server or Desktop"); } foreach (var document in documents) { try { session.AppendEvent(new VizqlEtc(document)); } catch (Exception ex) { Log.Error("Unable to create VizqlEtc record for " + session.VizqlSessionId + " for keyType " + keyType + ":" + ex.Message); } } } return(session); }
public object NotIn <TProperty>(string property, IEnumerable <TProperty> values) { return(InternalBuilder.Nin(property, values)); }
private static FilterDefinition <BsonDocument> FilterOutIgnoredClasses() { return(Query.Nin("class", BackgrounderConstants.IgnoredClasses)); }
// // 摘要: // Tests that the value of the named element is not equal to any of a list of values // (see $nin). // // 参数: // name: // The name of the element to test. // // values: // The values to compare to. // // 返回结果: // The builder (so method calls can be chained). public static FilterDefinition <BsonDocument> NotIn(string name, BsonArray values) { return(filter.Nin(name, values)); }