private IEnumerable <string> GetSubjectLink(IStoreGraph graph, string source, string segment) { if (string.Compare(segment, Constants.AnyPath, StringComparison.Ordinal) == 0) { return(graph.S(source).Where(x => x.Object.IsID).Select(x => x.Object.ToValue())); } else { return(graph.SP(source, segment).Where(x => x.Object.IsID).Select(x => x.Object.ToValue())); } }
private IEnumerable <string> GetByLevel(IStoreGraph graph, IEnumerable <string> sources, int level, bool isOutgoing) { if (level == 0) { return(Enumerable.Empty <string>()); } IEnumerable <string> next = new List <string>(); foreach (var source in sources) { var items = isOutgoing ? graph.S(source).Where(x => x.Object.IsID).Select(y => y.Object.Id).Distinct() : graph.O(source).Select(y => y.Subject).Distinct(); var targets = GetByLevel(graph, items, level - 1, isOutgoing); next = next.Concat(targets); } return(sources.Concat(next).Distinct()); }
public ObjectQueryResponse Query(ObjectQueryModel query, IStoreGraph graph) { query.PageSize = query.PageSize != 0 ? query.PageSize : Constants.DefaultPageSize; if (query.Id != null) { var item = graph.S(query.Id).FirstOrDefault(); return(new ObjectQueryResponse { Values = item != null ? new Triple[] { item } : new Triple[0], Continuation = null }); } if (query.Filter == null) { throw _storeErrors.AtLeastOneFilter; } var firstFilter = query.Filter.FirstOrDefault(); if (firstFilter.Key == null) { throw _storeErrors.AtLeastOneFilter; } var cTriple = query.Continuation != null ? new Triple( query.Continuation.S, query.Continuation.P, new TripleObject(query.Continuation.O, query.Continuation.IsId, query.Continuation.Index)) : null; var rsp = CreateConstraint(graph, firstFilter.Key, firstFilter.Value, cTriple); foreach (var filter in query.Filter.Skip(1)) { rsp = ApplyConstraint(rsp, graph, filter.Key, filter.Value); } if (query.HasObject != null) { foreach (var obj in query.HasObject) { rsp = ApplyOutgoing(rsp, graph, obj); } } if (query.HasSubject != null) { foreach (var sub in query.HasSubject) { rsp = ApplyIncoming(rsp, graph, sub); } } if (query.Aggregates == null || query.Aggregates.Length == 0) { var responseTriples = rsp.Take(query.PageSize).ToArray(); var cont = responseTriples.Length < query.PageSize ? null : responseTriples.LastOrDefault(); var queryResponse = new ObjectQueryResponse { Values = responseTriples, Continuation = cont != null ? new Continuation { S = cont.Subject, P = cont.Predicate, O = cont.Object.ToTypedJSON(), IsId = cont.Object.IsID, Index = cont.Object.Index } : null }; return(queryResponse); } // process aggregates return(ApplyAggregates(rsp, query.Aggregates)); }