コード例 #1
0
        private SearchDataModel GetExportDatas(QueryModel model, QueryExcelModel keyModel)
        {
            SearchDataModel searchDataModel            = new SearchDataModel();
            List <QueryExcelModelNoData> resultKeyList = new List <QueryExcelModelNoData>();
            List <ExportDataModel>       list          = new List <ExportDataModel>();
            var result = SearchData.SearchResult(model.SearchModel);

            if (result != null)
            {
                if (result.Response != null && result.Response.Docs.Count > 0)
                {
                    foreach (var d in result.Response.Docs)
                    {
                        ExportDataModel edm = new ExportDataModel();
                        edm.DocID = d.Id;
                        if (model.Score > 0)
                        {
                            edm.Score = model.Score;
                        }
                        else
                        {
                            edm.Score = null;
                        }
                        edm.ScoreType = model.ScoreType;
                        edm.SearchKey = model.SearchModel.SearchKey;
                        edm.QueryType = model.QueryType;

                        list.Add(edm);
                    }
                    resultKeyList.Add(new QueryExcelModelNoData()
                    {
                        ErrorType   = EnumErrorType.querySuccess.ToString(),
                        QueryString = keyModel.QueryString,
                        QueryID     = keyModel.QueryID,
                        QueryType   = keyModel.QueryType
                    });
                }
                else
                {
                    resultKeyList.Add(new QueryExcelModelNoData()
                    {
                        ErrorType   = EnumErrorType.SearchNoData.ToString(),
                        QueryString = keyModel.QueryString,
                        QueryID     = keyModel.QueryID,
                        QueryType   = keyModel.QueryType
                    });
                }
            }
            else
            {
                resultKeyList.Add(new QueryExcelModelNoData()
                {
                    ErrorType   = EnumErrorType.SearchError.ToString(),
                    QueryString = keyModel.QueryString,
                    QueryID     = keyModel.QueryID,
                    QueryType   = keyModel.QueryType
                });
            }

            searchDataModel.searchData = list;

            searchDataModel.queryResultList = resultKeyList;

            return(searchDataModel);
        }
コード例 #2
0
        private void tsbtnCreateData_Click(object sender, EventArgs e)
        {
            checkSearch();
            List <QueryExcelModel> KeyList = checkTemplate();

            List <ExportDataModel> list   = new List <ExportDataModel>();
            SearchModel            smodel = GetSearchModel();
            QueryModel             model  = GetQueryModel();

            var queryTypeList = KeyList.Select(q => q.QueryType).Distinct();

            List <QueryExcelModelNoData> errorResult     = new List <QueryExcelModelNoData>();
            Dictionary <string, int>     querySuccessKey = new Dictionary <string, int>();
            Dictionary <string, int>     queryErrorKey   = new Dictionary <string, int>();

            foreach (var qt in queryTypeList)
            {
                List <ExportDataModel> searchResultData = new List <ExportDataModel>();
                var queryKeyList = KeyList.Where(q => q.QueryType == qt).ToList();
                foreach (var kl in queryKeyList)
                {
                    lblnum.Text = string.Format("{0} :{1}", KeyList.IndexOf(kl).ToString(), kl.QueryString);
                    lblnum.Refresh();
                    smodel.SearchKey  = kl.QueryString;
                    model.SearchModel = smodel;

                    var data = GetExportDatas(model, kl);
                    searchResultData.AddRange(data.searchData);
                    if (data.queryResultList.Count > 0)
                    {
                        errorResult.AddRange(data.queryResultList.Where(q => q.ErrorType != EnumErrorType.querySuccess.ToString()));
                    }
                    if (data.searchData.Count > 0)
                    {
                        querySuccessKey.Add(kl.QueryString, data.searchData.Count);
                    }
                    else
                    {
                    }
                }
            }



            foreach (var kl in KeyList)
            {
                smodel.SearchKey  = kl.QueryString;
                model.SearchModel = smodel;



                var result = SearchData.SearchResult(smodel);

                if (result != null)
                {
                    if (result.Response != null && result.Response.Docs.Count > 0)
                    {
                        int j = result.Response.Docs.Count + 2;
                        foreach (var d in result.Response.Docs)
                        {
                            ExportDataModel edm = new ExportDataModel();
                            edm.DocID = d.Id;
                            edm.Score = j - result.Response.Docs.IndexOf(d);
                            //if (model.Score > 0)
                            //{
                            //    edm.Score = model.Score;
                            //}
                            //else
                            //{
                            //    edm.Score = null;
                            //}
                            edm.ScoreType = model.ScoreType;
                            edm.SearchKey = smodel.SearchKey;
                            edm.QueryType = kl.QueryType;

                            list.Add(edm);
                        }
                    }
                    else
                    {
                        KeyListSearchSuccess.Add(new QueryExcelModelNoData
                        {
                            ErrorType   = "SearchSuccess",
                            QueryID     = kl.QueryID,
                            QueryString = kl.QueryString,
                            QueryType   = kl.QueryType
                        });
                    }
                }
                else
                {
                    KeyListSearchError.Add(new QueryExcelModelNoData
                    {
                        ErrorType   = "SearchError",
                        QueryID     = kl.QueryID,
                        QueryString = kl.QueryString,
                        QueryType   = kl.QueryType
                    });
                }
            }

            if (list.Count > 0)
            {
                List <ExportObj> head = new List <ExportObj>();
                head.Add(new ExportObj {
                    DataType = typeof(string), key = "SearchKey", Name = "ScoreType"
                });
                head.Add(new ExportObj {
                    DataType = typeof(string), key = "DocID", Name = "DocID"
                });
                head.Add(new ExportObj {
                    DataType = typeof(decimal), key = "Score", Name = "Score"
                });
                head.Add(new ExportObj {
                    DataType = typeof(string), key = "ScoreType", Name = "ScoreType"
                });


                var queryTypeList = list.Select(q => q.QueryType).Distinct().ToList();
                foreach (var qt in queryTypeList)
                {
                    var    rpath    = rootpath + "/" + smodel.SearchType;
                    var    datalist = list.Where(q => q.QueryType == qt);
                    string filename = NPOIExcelHelper.ExportListToExcelNew(datalist.AsQueryable(), head, "ExportScoreData", rpath, qt);
                    if (!string.IsNullOrEmpty(filename))
                    {
                        KeyListSearchSuccess.Add(new QueryExcelModelNoData
                        {
                            ErrorType = "CreateSuccess",
                            //QueryID = kl.QueryID,
                            // QueryString = kl.QueryString,
                            QueryType = qt
                        });

                        this.txtKeyResult.Text = string.Format("查询类别:{0}  文件名称:{1}", qt, filename);
                        this.txtKeyResult.Refresh();
                    }
                    else
                    {
                        KeyListSearchError.Add(new QueryExcelModelNoData
                        {
                            ErrorType = "CreateError",
                            // QueryID = kl.QueryID,
                            //QueryString = kl.QueryString,
                            QueryType = qt
                        });
                    }
                }
            }
            else
            {
                KeyListSearchError.Add(new QueryExcelModelNoData
                {
                    ErrorType = "AllTemple Search NoData",
                    //QueryID = kl.QueryID,
                    //QueryString = kl.QueryString,
                    //QueryType = kl.QueryType
                });
            }

            errorlog(KeyListSearchError);

            this.btnCreateData.Enabled   = true;
            this.tsbtnCreateData.Enabled = true;
            string msg = string.Format("生成成功 {0} 条,生成失败 {1} 条", KeyListSearchSuccess.Count, KeyListSearchError.Count);

            this.txtKeyResult.Text = msg;
            this.txtKeyResult.Refresh();
            // MessageBox.Show(msg);
        }
コード例 #3
0
        private void toolStripLabel1_Click(object sender, EventArgs e)
        {
            checkSearch();
            List <QueryExcelModel> KeyList = checkTemplate();

            List <QueryExcelModelNoData> KeyListSearchSuccess = new List <QueryExcelModelNoData>();
            List <QueryExcelModelNoData> KeyListSearchError   = new List <QueryExcelModelNoData>();

            var rootpath = AppDomain.CurrentDomain.BaseDirectory + "/Export/ALL";


            List <ExportDataModel> list   = new List <ExportDataModel>();
            SearchModel            smodel = GetSearchModel();

            QueryModel model = GetQueryModel();

            foreach (var kl in KeyList)
            {
                smodel.SearchKey  = kl.QueryString;
                model.SearchModel = smodel;
                model.QueryType   = kl.QueryType;

                var result = SearchData.SearchResult(smodel);

                if (result != null)
                {
                    if (result.Response != null && result.Response.Docs.Count > 0)
                    {
                        int j = result.Response.Docs.Count + 2;
                        foreach (var d in result.Response.Docs)
                        {
                            ExportDataModel edm = new ExportDataModel();
                            edm.DocID = d.Id;
                            edm.Score = j - result.Response.Docs.IndexOf(d);
                            //if (model.Score > 0)
                            //{
                            //    edm.Score = model.Score;
                            //}
                            //else
                            //{
                            //    edm.Score = null;
                            //}
                            edm.ScoreType = model.ScoreType;
                            edm.SearchKey = smodel.SearchKey;
                            edm.QueryType = kl.QueryType;

                            list.Add(edm);
                        }
                    }
                    if (list.Count > 0)
                    {
                        List <ExportObj> head = new List <ExportObj>();
                        head.Add(new ExportObj {
                            DataType = typeof(string), key = "SearchKey", Name = "ScoreType"
                        });
                        head.Add(new ExportObj {
                            DataType = typeof(string), key = "DocID", Name = "DocID"
                        });
                        head.Add(new ExportObj {
                            DataType = typeof(decimal), key = "Score", Name = "Score"
                        });
                        head.Add(new ExportObj {
                            DataType = typeof(string), key = "ScoreType", Name = "ScoreType"
                        });


                        var    rpath    = rootpath + "/" + smodel.SearchType;
                        string filename = NPOIExcelHelper.ExportListToExcelNew(list.AsQueryable(), head, "ExportScoreData", rpath, kl.QueryID.ToString());
                        if (!string.IsNullOrEmpty(filename))
                        {
                            KeyListSearchSuccess.Add(new QueryExcelModelNoData
                            {
                                ErrorType   = "CreateSuccess",
                                QueryID     = kl.QueryID,
                                QueryString = kl.QueryString
                            });

                            this.txtKeyResult.Text = string.Format("序号:{0}  文件名称:{1}", kl.QueryID.ToString(), filename);
                            this.txtKeyResult.Refresh();
                        }
                        else
                        {
                            KeyListSearchError.Add(new QueryExcelModelNoData
                            {
                                ErrorType   = "CreateError",
                                QueryID     = kl.QueryID,
                                QueryString = kl.QueryString
                            });
                        }
                    }
                    else
                    {
                        KeyListSearchError.Add(new QueryExcelModelNoData
                        {
                            ErrorType   = "AllTemple Search NoData",
                            QueryID     = kl.QueryID,
                            QueryString = kl.QueryString
                        });
                    }
                }
                else
                {
                    KeyListSearchError.Add(new QueryExcelModelNoData
                    {
                        ErrorType   = "SearchError",
                        QueryID     = kl.QueryID,
                        QueryString = kl.QueryString,
                        QueryType   = kl.QueryType
                    });
                }

                lblnum.Text = string.Format("序号:{0}  关键字:{1}", KeyList.IndexOf(kl).ToString(), kl.QueryString);
                lblnum.Refresh();
            }

            errorlog(KeyListSearchError);

            this.btnCreateData.Enabled   = true;
            this.tsbtnCreateData.Enabled = true;
            string msg = string.Format("生成成功 {0} 条,生成失败 {1} 条", KeyListSearchSuccess.Count, KeyListSearchError.Count);

            this.txtKeyResult.Text = msg;
            this.txtKeyResult.Refresh();
        }