在使用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>";
                }
            }
        }

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