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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值