예제 #1
0
        //盘古测试查询
        private void button1_Click_1(object sender, EventArgs e)
        {
            FenCiHelper     fch       = new FenCiHelper();
            WycLuceneSearch wycsearch = new WycLuceneSearch();
            string          keyword   = this.textBox1.Text;
            string          keyto     = this.textBox1.Text;

            keyword = fch.PanguFenCi(keyword);//对关键字进行分词处理//fch.PanguFenCi(keyword);
            string line;
            //获取路径,循环每次都需要读取文本文件里设置的关键词
            string path    = Directory.GetCurrentDirectory();
            string txtpath = path + @"\App_Data\sDict.txt";
            //读取文本内容逐行
            StreamReader file = new StreamReader(txtpath);

            //分类操作,读取文本与标题分词判断
            string[] arr = keyword.Split('/');
            while ((line = file.ReadLine()) != null)
            {
                string[] arrtxt = line.Split(',');
                for (int j = 0; j < arr.Length; j++)
                {
                    if (arrtxt[0].Equals(arr[j]))
                    {
                        keyword = arrtxt[0] + keyto;//dt.Rows[i][3] += arrtxt[1] + ",";//类别
                        break;
                        //strtxt = arrtxt[1];//所属类别
                    }
                }
            }
            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, richTextBox1);//通过盘古分词搜索
                WycLuceneSearch.PanguQueryTest(analyzer, field, keyto, richTextBox2);
            }
        }
예제 #2
0
        //按标题搜索生成内容 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);
        }