JSP中实现全文检索

时间:2007-01-05 13:01:43   来源:  作者:  点击:次  出处:技术无忧
关键字:JSP中

 resultString=Html.TextEncode(resultString);


   myFileReader.close();

   //取出查询关键字

   Pattern p=null;

   Matcher m=null;

   p = Pattern.compile("//+");

   String[] a=p.split(keyWord);//把关键字用+分开

   //全文检索

   String searchResult="1";//检索结果

   int i;

   for(i=0;i<a.length;i++)//逐个按关键字查找,如果所有的关键字都符合,则记录结果

  {

   p = Pattern.compile(a[i].toString());

   m = p.matcher(resultString);

   if (!(m.find())) {

    searchResult="0";

      }

     }

  //记录符合条件的新闻    

  if(searchResult.equals("1")) 

  {

   News resultNews=new News();//存放结果的类,和数据库的结构基本一致

   resultNews.content=content;

   resultNews.release_time=release_time;

   resultNews.type=news_type;

   resultNews.man_add=man_add;

   resultNews.title=title;

   news.addElement(resultNews);//最后的结果集,要返回客户端

   }

   }

  //关闭数据库

  DbaObj.CloseConnection() ; 

    /SPAN>}catch(Exception e){

更多电脑、家电软硬件维修资讯请访问维修技术


相关文章

文章评论

共有 0 位网友发表了评论 此处只显示部分留言 点击查看完整评论页面

300x250广告位招租