internal static BsonDocument[] GetByName(string name) { name = MongoDbUtils.DotsToApostrophes(name.ToLower()); var pipeline = new[] { MQB.Match(MQB.And(new BsonDocument("name", name))), MQB.AddFields(new BsonDocument("namesegments", MQB.Split("$name", "'"))), MQB.AddFields(new BsonDocument("name", MQB.Substr(MQB.Reduce("$namesegments", "", MQB.Concat("$$value", ".", "$$this")), 1, -1))), MQB.Project(new BsonDocument("_id", 0).Add("assets", 0).Add("namesegments", 0)) }; return(pipeline); }
internal static BsonDocument[] GetWithTermsByDomain(string domain) { domain = MongoDbUtils.DotsToApostrophes(domain); var pipeline = new[] { MQB.Match(MQB.And(new BsonDocument("domain", domain))), MQB.AddFields(new BsonDocument("domsegments", MQB.Split("$domain", "'"))), MQB.AddFields(new BsonDocument("domain", MQB.Substr(MQB.Reduce("$domsegments", "", MQB.Concat("$$value", ".", "$$this")), 1, -1))), MQB.AddFields(new BsonDocument("terms", MQB.Filter("$terms", "term", MQB.And("$$term.scope", BASE_TERMS_SCOPE)))), MQB.AddFields(new BsonDocument("terms", MQB.ArrayElemAt("$terms", 0))), MQB.Project(new BsonDocument("domsegments", 0)) }; return(pipeline); }
internal static BsonDocument[] Filter(string name, bool startWith) { name = MongoDbUtils.DotsToApostrophes(name.ToLower()); string pattern = startWith ? $"/^{name}/" : $"/.*{name}.*/"; var pipeline = new[] { MQB.Match(MQB.And(new BsonDocument("name", new BsonRegularExpression(pattern)))), MQB.AddFields(new BsonDocument("namesegments", MQB.Split("$name", "'"))), MQB.AddFields(new BsonDocument("name", MQB.Substr(MQB.Reduce("$namesegments", "", MQB.Concat("$$value", ".", "$$this")), 1, -1))), MQB.Project(new BsonDocument("_id", 0).Add("assets", 0).Add("namesegments", 0)) }; return(pipeline); }