📄 forumsearch.java
字号:
package com.bcxy.bbs.forum;
/**
* Title:
* Description:
* Copyright:
* Company: www.liyunet.com
*
* @author lishujiang
* @version 1.0
*/
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.bcxy.bbs.util.BBSConst;
import com.bcxy.bbs.util.ParamUtil;
import com.bcxy.db.JdbcWrapper;
import com.bcxy.util.StringUtil;
public class ForumSearch {
private Logger log = Logger.getLogger(ForumSearch.class);
int searchTopicNum = 0;
String orderName = "";
public ForumSearch() {
}
public int getSearchTopicNum() {
return searchTopicNum;
}
public String getOrderName() {
return orderName;
}
public Vector getResult(HttpServletRequest request,
HttpServletResponse response) throws Exception {
Vector searchResult = new Vector();
JdbcWrapper jw = new JdbcWrapper();
try {
int forumID = ParamUtil.getInt(request, "forumID", 0);
int sType = ParamUtil.getInt(request, "sType");
int pSearch = ParamUtil.getInt(request, "pSearch", 0);
int nSearch = ParamUtil.getInt(request, "nSearch", 0);
String keyword = ParamUtil.getString(request, "keyword", "");
String searchForum = "";
if (sType < 1 || sType > 3){
throw new Exception("<li>对不起,请您选择搜索的类型");
}
String searchDate = "";
if (sType < 3) {
if (keyword == null || "".equals(keyword)) {
throw new Exception("<li>对不起,请您输入搜索得关键字");
}
if (forumID != 0){
searchForum = " b.boardid=" + forumID + " and ";
}
searchDate = ParamUtil.getString(request, "SearchDate");
if (searchDate == null || "".equals(searchDate)){
throw new Exception("<li>请您选择搜索的日期");
}
}
//int searchDateLimit = 30;
String searchDay = "";
if ("ALL".equals(searchDate)) {
// searchDay = " date_add(dateandtime,interval " +
// searchDateLimit
// + " DAY) > now() and ";
} else {
searchDay = " date_add(dateandtime,interval "
+ ParamUtil.getInt(request, "SearchDate", 0)
+ " DAY) > now() and ";
}
String guestlist = "";
String sql = "";
switch (sType) {
case 1:
switch (nSearch) {
// 搜索主题帖子作者
case 1:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b inner join " + BBSConst.TABLE_BOARD + " on b.boardid=" + BBSConst.TABLE_BOARD + ".boardid where b.username='"+keyword+"' and "
+ searchForum
+ " "
+ searchDay
+ " b.parentid=0 and b.locktopic!=2 ORDER BY b.announceID desc";
orderName = "搜索主题作者帖子";
break;
// 搜索回复帖子作者
case 2:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b inner join " + BBSConst.TABLE_BOARD + " on b.boardid=" + BBSConst.TABLE_BOARD + ".boardid where b.username='"+keyword+"' and "
+ guestlist
+ " "
+ searchForum
+ " "
+ searchDay
+ " b.parentid>0 and b.locktopic!=2 ORDER BY b.announceID desc";
orderName = "搜索回复作者帖子";
break;
// 两者都搜索
case 3:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b inner join " + BBSConst.TABLE_BOARD + " on b.boardid=" + BBSConst.TABLE_BOARD + ".boardid where "
+ guestlist
+ " "
+ searchForum
+ " "
+ searchDay
+ " b.username='"+keyword+"' and b.locktopic!=2 ORDER BY b.announceID desc";
orderName = "搜索主题和回复作者帖子";
break;
}
break;
case 2:
switch (pSearch) {
// 搜索主题关键字
case 1:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b inner join " + BBSConst.TABLE_BOARD + " on b.boardid=" + BBSConst.TABLE_BOARD + ".boardid where "
+ guestlist
+ " "
+ searchForum
+ " "
+ searchDay
+ " ( topic like '%"+keyword+"%' ) and b.locktopic!=2 ORDER BY b.announceID desc";
// 搜索内容关键字
orderName = "搜索主题";
break;
case 2:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b inner join " + BBSConst.TABLE_BOARD + " on b.boardid=" + BBSConst.TABLE_BOARD + ".boardid where "
+ guestlist
+ " "
+ searchForum
+ " "
+ searchDay
+ " ("
+ StringUtil.getTranslateSQL(keyword, "body")
+ ") and b.locktopic!=2 ORDER BY b.announceID desc";
// 两者都搜索
orderName = "搜索内容";
break;
case 3:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b inner join " + BBSConst.TABLE_BOARD + " on b.boardid=" + BBSConst.TABLE_BOARD + ".boardid where "
+ guestlist
+ " "
+ searchForum
+ " "
+ searchDay
+ " ("
+ StringUtil.getTranslateSQL(keyword, "topic")
+ " or "
+ StringUtil.getTranslateSQL(keyword, "body")
+ ") and b.locktopic!=2 ORDER BY b.announceID desc";
orderName = "搜索主题和内容";
break;
}
break;
case 3:
sql = "select b.locktopic,b.boardid,b.rootid,b.announceid,b.body,b.Expression,b.topic,b.username,b.child,b.hits,b.dateandtime," + BBSConst.TABLE_BOARD + ".lockboard from " + BBSConst.TABLE_BBS1 + " b," + BBSConst.TABLE_BOARD + " where "
+ guestlist
+ " b.boardid=" + BBSConst.TABLE_BOARD + ".boardid and b.locktopic!=2 ORDER BY b.announceID desc limit 0,50";
orderName = "最新50帖";
break;
}
if (sql.equals("")){
throw new Exception("<li>对不起,查询出错!");
}
int perPage = ParamUtil.getInt(request, "perPage", 10);
int Page = ParamUtil.getInt(request, "Page", 1);
int start = (Page - 1) * perPage;
//
jw.executeLimitQuery(sql, start, perPage);
searchTopicNum = jw.getAllRows();
while(jw.next()) {
ForumTopic theTopic = new ForumTopic();
theTopic.setLockTopic(jw.getInt(1));
theTopic.setForumID(jw.getInt(2));
theTopic.setRootID(jw.getInt(3));
theTopic.setAnnounceID(jw.getInt(4));
theTopic.setBody(jw.getString(5));
theTopic.setExpression(jw.getString(6));
theTopic.setTopic(jw.getString(7));
theTopic.setUserName(jw.getString(8));
theTopic.setChildNum(jw.getInt(9));
theTopic.setHits(jw.getInt(10));
theTopic.setDateAndTime(jw.getString(11));
//
searchResult.add(theTopic);
}
} catch (Exception e) {
log.error("查询论坛信息出错", e);
throw new Exception("查询数据库出错,请检查查询条件!");
} finally {
jw.close();
}
return searchResult;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -