ForumSearch.java
上传用户:toby834
上传日期:2013-10-21
资源大小:2613k
文件大小:8k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package net.acai.forum;
  2. /**
  3.  * Title:        清清网络
  4.  * Description:
  5.  * Copyright:    Copyright (c) 2002
  6.  * Company:      www.SuperSpace.com
  7.  * @author:       SuperSpace
  8.  * @version 1.0
  9.  */
  10. import net.acai.database.*;
  11. import java.sql.*;
  12. import net.acai.filter.*;
  13. import net.acai.util.*;
  14. import net.acai.forum.*;
  15. import net.acai.util.Format;
  16. import java.util.Vector;
  17. import javax.servlet.http.*;
  18. import net.acai.forum.util.*;
  19. import java.util.regex.*;
  20. public class ForumSearch
  21. {
  22. int searchTopicNum=0;
  23. String orderName="";
  24. public ForumSearch(){
  25. }
  26. public int getSearchTopicNum(){
  27. return searchTopicNum;
  28. }
  29. public String getOrderName(){
  30. return orderName;
  31. }
  32. public Vector getResult(HttpServletRequest request,HttpServletResponse response) throws Exception {
  33. Vector searchResult =new Vector();
  34. try{
  35. int forumID=ParamUtil.getInt(request,"forumID",0);
  36. int sType=ParamUtil.getInt(request,"sType");
  37. int pSearch=ParamUtil.getInt(request,"pSearch",0);
  38. int nSearch=ParamUtil.getInt(request,"nSearch",0);
  39. String keyword=ParamUtil.getString(request,"keyword","");
  40. String searchForum="";
  41. if(sType<1||sType>3)
  42. throw new Exception("<li>对不起,请您选择搜索的类型");
  43. String searchDate="";
  44. if(sType<3){
  45. if(keyword==null||"".equals(keyword))
  46. throw new Exception("<li>对不起,请您输入搜索得关键字");
  47. if(forumID!=0)
  48. searchForum=" b.boardid="+forumID+" and ";
  49. searchDate=ParamUtil.getString(request,"SearchDate");
  50. if(searchDate==null||"".equals(searchDate))
  51. throw new Exception("<li>请您选择搜索的日期");
  52. }
  53. int searchDateLimit=30;
  54. String searchDay;
  55. if ("ALL".equals(searchDate)){
  56. searchDay=" date_add(dateandtime,interval "+searchDateLimit+" DAY) > getdate()  and ";
  57. }
  58. else{
  59. searchDay="  date_add(dateandtime,interval "+ParamUtil.getInt(request,"SearchDate",0)+" DAY) > getdate()  and ";
  60. }
  61. String guestlist="";
  62. String sql="";
  63. //DBConnect dbc=new DBConnect(2,0);
  64. DBConnect dbc=new DBConnect();
  65. switch (sType){
  66. case 1:
  67. switch (nSearch){
  68. //搜索主题帖子作者
  69. case 1:
  70. sql="select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b inner join bbs.board on b.boardid=bbs.board.boardid where b.username=? and  "+searchForum+" "+searchDay+" b.parentid=0 ORDER BY b.announceID desc";
  71. orderName="搜索主题作者帖子";
  72. dbc.prepareStatement(sql);
  73. dbc.setBytes(1,(new String(keyword.getBytes("ISO-8859-1"),"GBK")).getBytes());
  74. break;
  75. //'搜索回复帖子作者
  76. case 2:
  77. sql="select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b inner join bbs.board on b.boardid=bbs.board.boardid where b.username=? and "+guestlist+" "+searchForum+" "+searchDay+" b.parentid>0 ORDER BY b.announceID desc";
  78. orderName="搜索回复作者帖子";
  79. dbc.prepareStatement(sql);
  80. dbc.setBytes(1,(new String(keyword.getBytes("ISO-8859-1"),"GBK")).getBytes());
  81. break;
  82. //'两者都搜索
  83. case 3:
  84. sql="select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b inner join bbs.board on b.boardid=bbs.board.boardid where "+guestlist+" "+searchForum+" "+searchDay+" b.username=? ORDER BY b.announceID desc";
  85. orderName="搜索主题和回复作者帖子";
  86. dbc.prepareStatement(sql);
  87. dbc.setBytes(1,(new String(keyword.getBytes("ISO-8859-1"),"GBK")).getBytes());
  88. break;
  89. }
  90. break;
  91. case 2:
  92. switch(pSearch){
  93. //'搜索主题关键字
  94. case 1:
  95. sql="select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b inner join bbs.board on b.boardid=bbs.board.boardid where  "+guestlist+" "+searchForum+" "+searchDay+" ( topic like ? ) ORDER BY b.announceID desc";
  96. //'搜索内容关键字
  97. orderName="搜索主题";
  98. dbc.prepareStatement(sql);
  99. dbc.setBytes(1,(new String(("%"+keyword+"%").getBytes("ISO-8859-1"),"GBK")).getBytes());
  100. break;
  101. case 2:
  102. sql="select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b inner join bbs.board on b.boardid=bbs.board.boardid where  "+guestlist+" "+searchForum+" "+searchDay+" (" + StringUtils.getTranslateStr(keyword,"body") + ") ORDER BY b.announceID desc";
  103. //'两者都搜索
  104. orderName="搜索内容";
  105. dbc.prepareStatement(sql);
  106. //dbc.setBytes(1,keyword.getBytes("GBK"));
  107. break;
  108. case 3:
  109. sql="select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b inner join bbs.board on b.boardid=bbs.board.boardid where  "+guestlist+" "+searchForum+" "+searchDay+" (" + StringUtils.getTranslateStr(keyword,"topic") + " or " + StringUtils.getTranslateStr(keyword,"body") + ") ORDER BY b.announceID desc";
  110. orderName="搜索主题和内容";
  111. dbc.prepareStatement(sql);
  112. //dbc.setBytes(1,keyword.getBytes("GBK"));
  113. break;
  114. }
  115. break;
  116. case 3:
  117. sql="select   b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime,board.lockboard from bbs.bbs1 b,bbs.board where "+guestlist+" b.boardid=bbs.board.boardid ORDER BY b.announceID desc";
  118. orderName="最新50帖";
  119. dbc.prepareStatement(sql);
  120. //dbc.setBytes(1,keyword.getBytes("GBK"));
  121. break;
  122. }
  123. if(sql.equals(""))
  124. throw new Exception("<li>对不起,sql语句出错!");
  125. int perPage=ParamUtil.getInt(request,"perPage",10);
  126. int Page=ParamUtil.getInt(request,"Page",1);
  127. int startPage=((Page-1)/10)*10+1;
  128. int start=(Page-1)*perPage+1;
  129. ResultSet rs=dbc.executeQuery(sql);
  130. /*
  131. if(rs.last())
  132. searchTopicNum=rs.getRow();
  133. if(start>searchTopicNum)
  134. return searchResult;
  135. rs.absolute(start);
  136. */
  137. //rs=dbc.executeQuery(sql);
  138. searchTopicNum = 0 ;
  139. while(rs.next())
  140. {
  141. searchTopicNum  ++ ;
  142. }
  143. if(start>searchTopicNum)
  144. return searchResult;
  145. rs=dbc.executeQuery(sql);
  146. int t = 1 ;
  147. if(t<start)
  148. {
  149. while(rs.next())
  150. {
  151. if(t==start)break;
  152. t++;
  153. }
  154. }
  155. int i=0;
  156. while(rs.next())
  157. {
  158. ForumTopic theTopic=new ForumTopic();
  159. theTopic.setLockTopic(rs.getInt(1));
  160. theTopic.setForumID(rs.getInt(2));
  161. theTopic.setRootID(rs.getInt(3));
  162. theTopic.setAnnounceID(rs.getInt(4));
  163. theTopic.setBody(rs.getString(5));
  164. theTopic.setExpression(rs.getString(6));
  165. theTopic.setTopic(rs.getString(7));
  166. theTopic.setUserName(rs.getString(8));
  167. theTopic.setChildNum(rs.getInt(9));
  168. theTopic.setHits(rs.getInt(10));
  169. theTopic.setDateAndTime(rs.getString(11));
  170. /*theTopic.setParentID(rs.getInt(2));
  171. theTopic.setUserEmail(rs.getString(6));
  172. theTopic.setLength(rs.getInt(11));
  173. theTopic.setLayer(rs.getInt(13));
  174. theTopic.setOrders(rs.getInt(14));
  175. theTopic.setIsBest(rs.getInt(15));
  176. theTopic.setUserIP(rs.getString(16));
  177. theTopic.setTimes(rs.getInt(18));
  178. theTopic.setSignFlag(rs.getInt(20));
  179. theTopic.setEmailFlag(rs.getInt(21));
  180. theTopic.setIsTop(rs.getInt(22));
  181. theTopic.setIsVote(rs.getInt(23));*/
  182. searchResult.add(theTopic);
  183. i++;
  184. if(i==perPage)
  185. break;
  186. if(sType==3&&i==50)break;
  187. }
  188. dbc.close();
  189. }
  190. catch(SQLException se)
  191. {
  192. se.printStackTrace();
  193. }
  194. catch(Exception e){
  195. throw e;
  196. }
  197.  return searchResult;
  198. }
  199. }