在使用lucene.net +盘古分词器 如果不输入关键字 查询全部的方法

string[] GetInfo ={ keyword, keyword, keyword };
            string[] Info ={ "title", "description", "content" };
//上面是对于的三个查询的字段和对于的key
            if (keyword == "")//如果传入的关键词是空..说明需求是查询全部的
            {
                Query p = new WildcardQuery(new Term("description", "*"));//虽然用的是盘古分词 但是还是可以使用这样的搜索方式进行查询全部
                BooleanQuery.SetMaxClauseCount(int.MaxValue);//最大查询的数量
                hits = search.Search(p);
            }
            else//如果有关键词 说明是有条件查询的
            {
                Query p = MultiFieldQueryParser.Parse(GetInfo, Info, new PanGuAnalyzer());//这里就用的是盘古的分词器了
                hits = search.Search(p);
            }
           
            GetPage = hits.Length();//查询总的数量
            for (int i = pageCount; i < PageAllCount; i++)//分页的方法
            {
                Document Doc = hits.Doc(i);
                PanGu.HighLight.SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color='red'>", "</font>");
                PanGu.HighLight.Highlighter highter = new Highlighter(simpleHTMLFormatter, new Segment());
                highter.FragmentSize = 200;
                string title = highter.GetBestFragment(keyword, Doc.Get("title"));
                string content = highter.GetBestFragment(keyword, Doc.Get("content"));
                string fb_time = Doc.Get("fb_time");
                string description = Doc.Get("description");
                string classc_cname = Doc.Get("classc_cname");
                string imageUrl = Doc.Get("imageurl");
                if (imageUrl == "")
                {
                    LitContent.Text += "<div class=\"txt\"><h2><a class=\"a55\" target=\"_blank\" href=\"info_68ea859e-994d-4cc0-b610-988549b6fa06.html\">" + title + "</a><span>" + classc_cname + "</span><b>" + fb_time + "</b></h2><dl><dt>" + Curstring(content, 150, true) + "<a href=\"#\">全文查看</a></dt></dl></div>";
                }
                else
                {
                    LitContent.Text += "<div class=\"txt\"><h2><a class=\"a55\" target=\"_blank\" href=\"info_68ea859e-994d-4cc0-b610-988549b6fa06.html\">" + title + "</a><span>" + classc_cname + "</span><b>" + fb_time + "</b></h2><dl><dd><img alt=\"\" src=\"http://www.madeinchina.cn/" + imageUrl + "\"></dd><dt>" + Curstring(content, 150, true) + "<a href=\"#\">全文查看</a></dt></dl></div>";
                }
            }
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章