public QuerySpecificationBuilderImpl( SQLVendor vendor, SelectColumnClauseBuilder columnsBuilder, FromBuilder fromBuilder, BooleanBuilder whereBuilder, GroupByBuilder groupByBuilder, BooleanBuilder havingBuilder, OrderByBuilder orderByBuilder ) : base(vendor) { ArgumentValidator.ValidateNotNull(nameof(columnsBuilder), columnsBuilder); ArgumentValidator.ValidateNotNull(nameof(fromBuilder), fromBuilder); ArgumentValidator.ValidateNotNull(nameof(whereBuilder), whereBuilder); ArgumentValidator.ValidateNotNull(nameof(groupByBuilder), groupByBuilder); ArgumentValidator.ValidateNotNull(nameof(havingBuilder), havingBuilder); ArgumentValidator.ValidateNotNull(nameof(orderByBuilder), orderByBuilder); this._colsBuilder = columnsBuilder; this._fromBuilder = fromBuilder; this._whereBuilder = whereBuilder; this._groupByBuilder = groupByBuilder; this._havingBuilder = havingBuilder; this._orderByBuilder = orderByBuilder; }
public List <LogDetalleUsuario> GetDatosRetoEquipo2(Reto reto) { List <LogDetalleUsuario> lst = new List <LogDetalleUsuario>(); var r = GetEquipos(reto.Equipos); Parallel.ForEach(r, (e) => { IMongoGroupBy group = new GroupByBuilder(new[] { "FechaHora", "Usuario" }); var key = "FechaHora, Usuario"; var initial = new BsonDocument("SumConteo", 0); var reduce = @"function(obj, prev) { prev.SumConteo = prev.SumConteo + obj.Conteo - 0; }"; var query = Query.And(new[] { Query.In("Usuario", new BsonArray(e.Miembros)), Query.GTE("FechaHora", reto.FechaInicio), Query.LTE("FechaHora", reto.FechaFin) }); var l = GetCollection <LogEjercicio>(Settings.Default.CollectionLogEjercicio) .Group(query, group, initial, reduce, null) .ToList(); foreach (var a in l) { lst.Add(BsonSerializer.Deserialize <LogDetalleUsuario>(a)); Console.WriteLine("{0}", a.ToString()); } }); return(lst); }
/// <summary> /// 查询groupby数据 /// </summary> /// <typeparam name="T">数据类型</typeparam> /// <param name="keys">主键列表</param> /// <param name="collectionName">表名</param> /// <param name="query">查询</param> /// <param name="filter">查询条件</param> /// <param name="javascriptReduce">脚本</param> /// <param name="javascriptFinalize">脚本2</param> /// <returns>查询groupby数据</returns> public IEnumerable <BsonDocument> QueryGroupby <T>(string[] keys, string collectionName, IMongoQuery query, BaseFilter filter, string javascriptReduce, string javascriptFinalize) { MongoCollection collection = GetMongoCollection(collectionName); GroupByBuilder groupbyBuilder = new GroupByBuilder(keys); BsonDocument doc = new BsonDocument(); return(collection.Group(query, groupbyBuilder, doc, BsonJavaScript.Create(javascriptReduce), BsonJavaScript.Create(javascriptFinalize))); }
public PagedSelectCommandBuilder Clear() { SelectBuilder.Clear(); FromBuilder.Clear(); WhereBuilder.Clear(); OrderByBuilder.Clear(); GroupByBuilder.Clear(); HavingBuilder.Clear(); CommandParameters.Clear(); Distinct = false; Offset = 0; PageSize = 0; return(this); }
public PagedSelectCommandBuilder GroupBy(string value) => this.Chain(() => GroupByBuilder.Append(value));
public static GroupByBuilder AddGroupingElementsP(this GroupByBuilder builder, params GroupingElement[] elements) { return(builder.AddGroupingElements(elements)); }
public IHttpActionResult Get([FromUri] Request <Info> request) { if (request.Type == -1) { MongoCollection data = database.GetCollection("info"); GroupByBuilder groupbyBuilder = new GroupByBuilder(new string[] { "CategoryCode", "CategoryName" }); Dictionary <string, int> dic_F = new Dictionary <string, int>(); dic_F["num"] = 0; var result_F = data.Group(null, groupbyBuilder, BsonDocument.Create(dic_F), BsonJavaScript.Create("function(doc,prev){prev.num++;}"), BsonJavaScript.Create("function(doc){doc.Count=doc.num;delete doc.num;}")).ToList(); /*List<InfoAllList> list = new List<InfoAllList>(); * if (result_F.Count > 0) * { * foreach (var item in result_F) * { * InfoAllList temp = new InfoAllList(); * temp.CategoryCode = item["CategoryCode"].AsString; * temp.CategoryName = item["CategoryName"].AsString; * temp.Count = item["Count"].AsDouble.ToString().ToInt(0); * list.Add(temp); * } * }*/ Response <List <BsonDocument> > rsp = new Response <List <BsonDocument> >(); rsp.Data = result_F; return(Ok(rsp)); } if (request.ID == "SearchInfo") { Response <List <InfoModel> > rsp = new Response <List <InfoModel> >(); if (string.IsNullOrEmpty(request.Keyword)) { return(Ok(rsp)); } List <InfoModel> list = new List <InfoModel>(); #region 1、在mongodb查询匹配的Info对象 IMongoQuery query = null; if (request.UserName == "Title") { query = Query <Info> .Matches(c => c.Title, new BsonRegularExpression(new Regex(request.Keyword + ".*"))); } else if (request.UserName == "Author") { query = Query <Info> .Matches(c => c.Author, new BsonRegularExpression(new Regex(request.Keyword + ".*"))); } else if (request.UserName == "Source") { query = Query <Info> .Matches(c => c.Source, new BsonRegularExpression(new Regex(request.Keyword + ".*"))); } else if (request.UserName == "Digest") { query = Query <Info> .Matches(c => c.Digest, new BsonRegularExpression(new Regex(request.Keyword + ".*"))); } else if (request.UserName == "KeyWord") { query = Query <Info> .Matches(c => c.KeyWord, new BsonRegularExpression(new Regex(request.Keyword + ".*"))); } else if (request.UserName == "CategoryCode") { query = Query <Info> .Matches(c => c.CategoryCode, new BsonRegularExpression(new Regex(request.Keyword))); } if (query != null) { var data = database.GetCollection("info").Find(query).ToList(); foreach (var item in data) { InfoModel temp = new InfoModel(); temp.InfoId = item.GetValue("_id").ToString(); temp.Title = item.GetValue("Title").ToString(); Dictionary dic = getArticleClassNameFoo(item.GetValue("CategoryCode").ToString()); if (dic != null) { temp.ArticleClass = dic.value; } temp.ArticleCategory = item.GetValue("CategoryName").ToString(); temp.Author = item.GetValue("Author").ToString(); string extStr = item.GetValue("ArticleType").ToString(); string[] arr = extStr.Split('、'); if (arr.Length > 0) { temp.FileType = arr[0]; } else { temp.FileType = "1176708"; } string fileUrl = ""; string dbFileName = item.GetValue("FileName").AsString.Trim(); if (!string.IsNullOrEmpty(dbFileName)) { fileUrl = "/Upload/" + dbFileName; } /*if (item.GetValue("FileName").ToString().Trim().EndsWith(".xls") || item.GetValue("FileName").ToString().Trim().EndsWith(".xlsx")) * { * fileUrl += "XLS/"; * } * fileUrl += item.GetValue("FileId").ToString().Trim() + "/" + item.GetValue("FileName").ToString().Trim();*/ temp.FilePath = fileUrl; temp.PublishTime = item.GetValue("PublishTime").AsDateTime; temp.ArticleType = item.GetValue("ArticleType").AsString; temp.ModifyTime = item.GetValue("ModifyTime").AsDateTime; temp.ModifyUser = item.GetValue("ModifyUser").AsString; list.Add(temp); } } #endregion if (request.UserName == "Content") { #region 2、查询solr服务器来搜索文件内容 string q = "text:" + request.Keyword; string url = SolrUrl + "select?q=" + HttpUtility.UrlEncode(q) + "&rows=1000000&wt=json&_=" + StringExtension.getTimeStamp(DateTime.Now); HttpClient client = new HttpClient(); string result = client.GetStringAsync(url).Result; SolrContext sc = result.JsonDeserialize <SolrContext>(); #endregion #region 3、通过solr搜索结果来匹配数据库 foreach (var item in sc.response.docs) { FileInfo fi = new FileInfo(item.uri); string dirName = fi.Directory.Name; var query2 = Query.EQ("FileId", dirName); Info info = database.GetCollection("info").FindAs <Info>(query2).FirstOrDefault(); if (info == null) { continue; } if (info.FileName != fi.Name) { continue; } InfoModel temp = new InfoModel(); temp.InfoId = info._id.ToString(); temp.Title = info.Title; Dictionary dic = getArticleClassNameFoo(info.CategoryCode); if (dic != null) { temp.ArticleClass = dic.value; } temp.ArticleCategory = info.CategoryName; temp.Author = info.Author; string extStr = info.ArticleType; string[] arr = extStr.Split('、'); if (arr.Length > 0) { temp.FileType = arr[0]; } else { temp.FileType = "1176708"; } string fileUrl = "/Upload/"; if (fi.Extension == ".xls" || fi.Extension == ".xlsx") { fileUrl += "XLS/"; } fileUrl += info.FileId + "/" + info.FileName; temp.FilePath = fileUrl; if (list.Contains(temp)) { continue; } list.Add(temp); } #endregion } rsp.Data = list; if (request.UserName == "CategoryCode") { List <InfoModel> result = list.Skip((request.CurrentPage - 1) * PageSize).Take(PageSize).ToList(); int count = list.Count / PageSize; if (list.Count % PageSize > 0) { count += 1; } rsp.PagesCount = count; rsp.Data = result; } return(Ok(rsp)); } else { Guid g = new Guid(); if (Guid.TryParse(request.Keyword, out g)) { Dictionary dic = _dictionary.GetDictionaryById(g.ToString()); List <string> nodeIds = new List <string>(); nodeIds.Add(dic.nodeId); Foo(nodeIds, dic); Response <List <Info> > response = new Response <List <Info> >(); var list = database.GetCollection <Info>("info").FindAll().ToList(); List <Info> result = new List <Info>(); foreach (string item in nodeIds) { Info temp = list.Find(p => p.CategoryCode == item); if (temp != null) { result.Add(temp); } } response.Data = result; return(Ok(response)); } else { Response <List <Info> > response = new Response <List <Info> >(); var list = database.GetCollection <Info>("info").FindAll().ToList(); if (!string.IsNullOrEmpty(request.Keyword)) { list = list.FindAll(p => p.Title.Contains(request.Keyword) || p.Html.Contains(request.Keyword) || p.Author.Contains(request.Keyword)); } response.Data = list; return(Ok(response)); } } }