//获取db3数据库内容总数 //public int GetTotal(GetTotalDelegate gettotaldelegate) //{ // int total = 0; // //DataTable dt = new SqliteHelper().SqliteQuery("select * from [Content]").Tables[0]; // int num = new SqliteHelper().GetMaxID("ID", "Content"); // if (num > 0) // { // for (int i = 0; i < num; i++) // { // total++; // gettotaldelegate(total); // } // } // return total; //} //根据txt文件里行数调整进度条 public int GetTitleTotal(GetTitletotal gettitletot) { int total = 0; //获取路径,循环每次都需要读取文本文件里设置的关键词 string path = Directory.GetCurrentDirectory(); string titlepath = path + @"\App_Data\sytitle.txt"; StreamReader file = new StreamReader(titlepath, System.Text.Encoding.GetEncoding("GB2312")); string strFile = file.ReadToEnd(); //获取所有行 string[] arraFile = strFile.Split('\n'); for (int i = 0; i < arraFile.Length; i++) { total++; gettitletot(total); } return(total); }
//按标题搜索生成内容 2012-6-5创建 public void ShengChengNeiRong(GetTitletotal getTotalRecordsDelegate, System.Diagnostics.Stopwatch sw, System.Windows.Forms.RichTextBox rich) { int totalRecords = 0; wznr_Servise wznr = new wznr_Servise(); DataTable newdt = wznr.GetNeiRongTable(); DataRow newdr; FenCiHelper fch = new FenCiHelper(); //获取路径,循环每次都需要读取文本文件里设置的关键词 string path = Directory.GetCurrentDirectory(); string titlepath = path + @"\App_Data\sytitle.txt"; StreamReader file = new StreamReader(titlepath, System.Text.Encoding.GetEncoding("GB2312")); string keyword; //文章标题行 string line; //关键词行 string strFile = file.ReadToEnd(); //获取所有行 string[] arraFile = strFile.Split('\n'); string tongyicititle;//同义词标题 for (int i = 0; i < arraFile.Length; i++) { totalRecords++; getTotalRecordsDelegate(totalRecords); string key = arraFile[i]; //tongyicititle = fch.PanGuFenCiTYC( arraFile[i]);//输出同义词标题 keyword = fch.PanguFenCi(arraFile[i]); string[] arr = keyword.Split('/'); string txtpath = path + @"\App_Data\sDict.txt"; //读取文本内容逐行 StreamReader file1 = new StreamReader(txtpath); while ((line = file1.ReadLine()) != null) { string[] arrtxt = line.Split(','); for (int j = 0; j < arr.Length; j++) { if (arrtxt[0].Equals(arr[j])) { keyword = arrtxt[0] + key; rich.Text += keyword; rich.ForeColor = System.Drawing.Color.Green;//ConsoleColor.Green; break; } } } string field = "contents"; //搜索的对应字段 string[] fieldArr = new string[] { field, "title" }; //两个字段 string rangeField = "createdate"; //范围搜索对应字段 IList <Analyzer> listAnalyzer = WycLuceneAnalyzer.BuildAnalyzers(); //LuceneAnalyzer.BuildAnalyzers(); BooleanClause.Occur[] occurs = new BooleanClause.Occur[] { BooleanClause.Occur.MUST, BooleanClause.Occur.SHOULD }; foreach (Analyzer analyzer in listAnalyzer) { WycLuceneSearch.PanguQueryTest(analyzer, field, keyword, rich);//通过盘古分词搜索 } newdr = newdt.NewRow(); newdr["Title"] = key;//keyword;//tongyicititle; newdr["p"] = rich.Text; newdt.Rows.Add(newdr); } string sqlp = "insert into test5Table (Title,p)" + " SELECT nc.Title,nc.p" + " FROM @NewBulkTestTvp AS nc"; sw.Start(); wznr.TableValuedToDB(newdt, sqlp, "dbo.test5Udt"); sw.Stop(); getTotalRecordsDelegate(totalRecords); }