コード例 #1
0
ファイル: UserService.cs プロジェクト: BULUSDUAN/lottery_PC
        /// <summary>
        /// 多表查询
        /// </summary>
        /// <returns></returns>
        private Task <int> Test2()
        {
            //两张表
            var uQueryUser   = DB.CreateQuery <EntityModel.User>();
            var uQueryRelate = DB.CreateQuery <EntityModel.Relate>();

            #region 查询全部

            var allQuery = from b in uQueryUser
                           join c in uQueryRelate
                           on b.Relate_ID equals c.ID
                           select new EntityModel.User
            {
                ID         = b.ID,
                Name       = b.Name,
                Relate_ID  = b.ID,
                RelateName = c.Name
            };
            var p1 = allQuery.ToList();

            #endregion


            #region 条件查询
            var p2 = allQuery.Where(b => b.ID > 1).ToList <EntityModel.User>();
            #endregion



            #region  条件分页查询
            QueryArgs  queryAga = new QueryArgs();
            var        wlist    = new List <WhereField>();
            WhereField wf       = new WhereField()
            {
                WhereType = WhereType.Like,
                Field     = "test_name",
                Value     = "用户"
            };
            wlist.Add(wf);

            queryAga.WhereFields = wlist;

            var result = DB.CreateComQuery().Query <User>(allQuery, queryAga);//.toResult();
            #endregion



            #region json 分页查询
            QuerySearchModel qsModel = new QuerySearchModel();
            string           str     = JsonHelper.Serialize(wlist);

            qsModel.Filters = str;
            var args    = qsModel.toQuery();
            var result1 = DB.CreateComQuery().Query <User>(allQuery, args);
            #endregion


            return(Task.FromResult(1));
        }
コード例 #2
0
        public object Search(string keyword, int page, int rows)
        {
            QuerySearchModel query = new QuerySearchModel();

            query.queryExp = keyword;
            query.restype  = 0;
            query.isSearch = true;
            query.page     = page;
            query.rows     = rows;
            return(SearchExtend(query));
        }
コード例 #3
0
ファイル: UserService.cs プロジェクト: BULUSDUAN/lottery_PC
        /// <summary>
        /// 单表查询
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        private Task <int> Test1()
        {
            var uQuery = DB.CreateQuery <EntityModel.User>();

            #region 查询全部
            var allList = uQuery.ToList();
            #endregion


            #region 条件查询
            var p = uQuery.Where(b => b.ID > 0 && b.Name.Contains("用户")).ToList <EntityModel.User>();
            #endregion



            #region  条件分页查询
            QueryArgs  queryAga = new QueryArgs();
            var        wlist    = new List <WhereField>();
            WhereField wf       = new WhereField()
            {
                WhereType = WhereType.Like,
                Field     = "test_name",
                Value     = "用户"
            };
            wlist.Add(wf);

            queryAga.WhereFields = wlist;

            var result = DB.CreateComQuery().Query <User>(uQuery, queryAga);//.toResult();
            #endregion



            #region json 分页查询
            QuerySearchModel qsModel = new QuerySearchModel();
            string           str     = JsonHelper.Serialize(wlist);

            qsModel.Filters = str;
            var args    = qsModel.toQuery();
            var result1 = DB.CreateComQuery().Query <User>(uQuery, args);
            #endregion


            return(Task.FromResult(1));
        }
コード例 #4
0
        private string FormatArguments(Dictionary <string, object> args)
        {
            string argstring = "";

            if (args == null)
            {
                return("");
            }
            foreach (var item in args)
            {
                if (item.Value is QuerySearchModel)
                {
                    QuerySearchModel model = (QuerySearchModel)item.Value;
                    argstring += string.Format("{0}@{1}@{2}@{3}@{4}", model.queryExp, model.restype, model.rows, model.sortExp, model.groupName);
                }
                else
                {
                    argstring += string.Format("{0}----{1}&", item.Key, item.Value == null ? "" : item.Value.ToString());
                }
            }
            return(argstring);
        }
コード例 #5
0
        // GET: Search
        public async Task <ActionResult> Index([Bind(Include = "q")] QuerySearchModel query)
        {
            if (!string.IsNullOrEmpty(User.Identity.Name))
            {
                if (_telegramService.IsIdentityRequired())
                {
                    var user = await UserManager.FindByNameAsync(User.Identity.Name);

                    if (user != null)
                    {
                        try
                        {
                            TempData["AuthHash"] = await _telegramService.AuthAsync(user.PhoneNumber);

                            return(RedirectToAction("CodeConfirm"));
                        }
                        catch { }
                    }
                }
            }
            return(View("Index", query));
        }
コード例 #6
0
        public object SearchExtend(QuerySearchModel query)
        {
            if (query == null)
            {
                return new { Rcode = -1, Rmsg = "错误请求" }
            }
            ;

            string       errmsg  = null;
            TimeSpan     usetime = new TimeSpan();
            SearchResult result  = SearchBLL.SearchQuery(query, ref usetime, ref errmsg);

            if (!string.IsNullOrEmpty(errmsg) || result == null)
            {
                return new { Rcode = -1, Rmsg = errmsg }
            }
            ;
            else if (result.TotalCount == 0)
            {
                return new { Rcode = 0, total = 0, Rmsg = "没有符合条件的数据" }
            }
            ;
            else
            {
                if (string.IsNullOrEmpty(query.groupName))
                {
                    DataTable rdt = new DataTable();
                    //   int pagecount = result.ResultCount % query.rows == 0 ? result.ResultCount / query.rows : result.ResultCount / query.rows + 1;
                    if (result.Attrs != null && result.Attrs.Length > 0)
                    {
                        rdt.Columns.Add(new DataColumn("seqid"));
                        foreach (AttrMatch am in result.Attrs)
                        {
                            rdt.Columns.Add(new DataColumn(am.AttrName));
                        }
                    }
                    DataRow dr;
                    foreach (ResultMatches match in result.Matches)
                    {
                        dr          = rdt.NewRow();
                        dr["seqid"] = match.DocumentID;
                        foreach (DataColumn dc in rdt.Columns)
                        {
                            if (dc.ColumnName != "seqid")
                            {
                                dr[dc.ColumnName] = match.GetAttrValue(dc.ColumnName);
                            }
                        }
                        rdt.Rows.Add(dr);
                    }
                    return(new
                    {
                        Rcode = 1,
                        list = rdt,
                        total = result.TotalCount,
                        PageCount = result.TotalCount,
                        usetime = usetime.TotalMilliseconds
                    });
                }
                else
                {
                    int            classparentid = 12;
                    string         _errmsg;
                    List <Options> optionlist = null;
                    switch (query.groupName.Trim())
                    {
                    case "restype":
                        SearchBLL.GetResTypeOptions(out _errmsg);
                        optionlist = SearchBLL.restypeList;
                        break;

                    case "classid":
                        SearchBLL.GetClassOptions(classparentid, out _errmsg);
                        optionlist = SearchBLL.classList[classparentid];
                        break;

                    case "languageid":
                        SearchBLL.GetDicOptions(out _errmsg);
                        optionlist = SearchBLL.dictList["language"];
                        break;

                    case "authorstr":
                        SearchBLL.GetAuthorOptions(out _errmsg);
                        optionlist = SearchBLL.authorsList;
                        break;
                    }
                    List <SearchGroupModel> grouplist = new List <SearchGroupModel>();
                    SearchGroupModel        group;
                    foreach (ResultMatches match in result.Matches)
                    {
                        group            = new SearchGroupModel();
                        group.groupvalue = match.GetAttrValue("@groupby").ToString().Trim();
                        group.groupcount = int.Parse(match.GetAttrValue("@count").ToString());
                        Options option = optionlist != null?optionlist.Find(o => o.id == group.groupvalue) : null;

                        if (option != null)
                        {
                            group.groupname = option.text;
                        }
                        else
                        {
                            group.groupname = group.groupvalue;
                        }
                        grouplist.Add(group);
                    }
                    if (query.groupName.Trim().Equals("classid"))
                    {
                        grouplist = SearchBLL.GetClassGroupTree(classparentid, grouplist);
                    }
                    return(new
                    {
                        Rcode = 1,
                        list = grouplist,
                        total = result.TotalCount,
                        PageCount = result.TotalCount,
                        usetime = usetime.TotalMilliseconds
                    });
                }
            }
        }
コード例 #7
0
ファイル: SearchBLL.cs プロジェクト: xiaosachuchen/-version2
        /// <summary>
        /// 获取检索结果
        /// </summary>
        /// <param name="query">检索对象</param>
        /// <param name="usetime">检索用时</param>
        /// <param name="errmsg">错误信息</param>
        /// <returns>检索结果</returns>
        public static SearchResult SearchQuery(QuerySearchModel query, ref TimeSpan usetime, ref string errmsg)
        {
            ISeeClient      ISee           = new ISeeClient();
            ISeeIndexServer ISeeServerInfo = GetISeeServer(query.restype);

            if (ISeeServerInfo == null)
            {
                errmsg = "未获取到对应索引:" + query.restype;
                return(null);
            }
            ISee.Ip            = ISeeServerInfo.IP;
            ISee.Port          = ISeeServerInfo.Port;
            ISee.AutoFilterTag = false;// ISeeServerInfo.AutoFilterTag;
            ISee.MaxMatchCount = ISeeServerInfo.MaxMatchCount;
            ISee.SearchMode    = SearchMode.MatchExtended2;
            if (query.rows <= 0)
            {
                query.rows = ISeeServerInfo.MaxMatchCount;
            }

            SearchOptions option = new SearchOptions();

            option.Limit  = query.rows;
            option.Offset = (query.page - 1) * query.rows;
            option.Offset = option.Offset + ISee.Limit > ISeeServerInfo.MaxMatchCount ? (ISeeServerInfo.MaxMatchCount - ISee.Limit) : option.Offset;
            option.Index  = ISeeServerInfo.Index;
            FilterAttrs(query.queryExp, query.restype, ref option, out errmsg);
            if (!string.IsNullOrEmpty(errmsg))
            {
                return(null);
            }
            // 分组字段
            if (!string.IsNullOrEmpty(query.groupName))
            {
                option.GroupAttrName = query.groupName;
                option.ResultAttrs   = query.groupName;
                // 分组排序
                GroupSort groupSort = GroupSort.CountDesc;
                if (!string.IsNullOrEmpty(query.sortExp) && Enum.TryParse <GroupSort>(query.sortExp, out groupSort))
                {
                    option.GroupSort = groupSort;
                }
                else
                {
                    option.GroupSort = GroupSort.CountDesc; // 默认
                }
            }
            else
            {
                // 排序
                if (!string.IsNullOrEmpty(query.sortExp))
                {
                    option.SortExp = query.sortExp;
                }
                //查询词计数
                //if (!string.IsNullOrEmpty(option.KeyExp))
                //{
                //    if (query.isSearch)
                //    {
                //        string _errmsg;
                //        Regex regex = new Regex("[\u4e00-\u9fa5]+");
                //        Dictionary<string, int> keylist = new Dictionary<string, int>();
                //        foreach (Match match in regex.Matches(option.KeyExp))
                //        {
                //            if (match.Success && match.Groups.Count > 0 && !keylist.ContainsKey(match.Groups[0].Value))
                //                keylist.Add(match.Groups[0].Value, 0);
                //        }
                //        if (keylist.Count > 0)
                //        {
                //            string[] keyarr = new string[keylist.Count];
                //            int i = 0;
                //            foreach (string key in keylist.Keys)
                //            {
                //                keyarr[i] = key;
                //                i++;
                //            }
                //            DAL.SearchDAL.UpdateHotKeyData(keyarr, out _errmsg);
                //        }
                //    }
                //}
            }
            // 查询结果
            SearchResult results = ISee.Query(option);

            if (!string.IsNullOrEmpty(ISee.ErrMsg))
            {
                errmsg = ISee.ErrMsg;
                return(null);
            }
            if (!string.IsNullOrEmpty(results.Warnmsg))
            {
            }
            usetime = ISee.FoundTime;
            return(results);
        }