⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 forumsearch.java

📁 阿菜论坛beta-1版java代码
💻 JAVA
字号:
package net.acai.forum;
/**
 * Title:        阿菜网络
 * Description:
 * Copyright:    Copyright (c) 2002
 * Company:      www.justhis.com
 * @author:       acai
 * @version 1.0
 */
import net.acai.database.*;
import java.sql.*;
import net.acai.filter.*;
import net.acai.util.*;
import net.acai.forum.*;
import net.acai.util.Format;
import java.util.Vector;
import javax.servlet.http.*;
import net.acai.forum.util.*;
import java.util.regex.*;

public class ForumSearch
{
	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();
		
		
		
		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="";
			DBConnect dbc=new DBConnect(2,0);
			
			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,board.lockboard from bbs1 b inner join board on b.boardid=board.boardid where b.username=? and  "+searchForum+" "+searchDay+" b.parentid=0 ORDER BY b.announceID desc";
				orderName="搜索主题作者帖子";
				
				dbc.prepareStatement(sql);
				dbc.setBytes(1,keyword.getBytes("GBK"));
				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,board.lockboard from bbs1 b inner join board on b.boardid=board.boardid where b.username=? and "+guestlist+" "+searchForum+" "+searchDay+" b.parentid>0 ORDER BY b.announceID desc";
				orderName="搜索回复作者帖子";
				dbc.prepareStatement(sql);
				dbc.setBytes(1,keyword.getBytes("GBK"));
				
				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,board.lockboard from bbs1 b inner join board on b.boardid=board.boardid where "+guestlist+" "+searchForum+" "+searchDay+" b.username=? ORDER BY b.announceID desc";
				orderName="搜索主题和回复作者帖子";
				dbc.prepareStatement(sql);
				dbc.setBytes(1,keyword.getBytes("GBK"));
				
				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,board.lockboard from bbs1 b inner join board on b.boardid=board.boardid where  "+guestlist+" "+searchForum+" "+searchDay+" ( topic like ? ) ORDER BY b.announceID desc";
				//'搜索内容关键字
				orderName="搜索主题";
				dbc.prepareStatement(sql);
				dbc.setBytes(1,("%"+keyword+"%").getBytes("GBK"));
				
				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,board.lockboard from bbs1 b inner join board on b.boardid=board.boardid where  "+guestlist+" "+searchForum+" "+searchDay+" (" + StringUtils.getTranslateStr(keyword,"body") + ") ORDER BY b.announceID desc";
				//'两者都搜索
				orderName="搜索内容";
				dbc.prepareStatement(sql);
				//dbc.setBytes(1,keyword.getBytes("GBK"));
				
				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,board.lockboard from bbs1 b inner join board on b.boardid=board.boardid where  "+guestlist+" "+searchForum+" "+searchDay+" (" + StringUtils.getTranslateStr(keyword,"topic") + " or " + StringUtils.getTranslateStr(keyword,"body") + ") ORDER BY b.announceID desc";
				orderName="搜索主题和内容";
				dbc.prepareStatement(sql);
				//dbc.setBytes(1,keyword.getBytes("GBK"));
				
				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,board.lockboard from bbs1 b,board where "+guestlist+" b.boardid=board.boardid ORDER BY b.announceID desc limit 0,50";
				orderName="最新50帖";
				dbc.prepareStatement(sql);
				//dbc.setBytes(1,keyword.getBytes("GBK"));
				
				break;
			}
			
			if(sql.equals(""))
				throw new Exception("<li>对不起,sql语句出错!");


			int perPage=ParamUtil.getInt(request,"perPage",10);
			int Page=ParamUtil.getInt(request,"Page",1);
			int startPage=((Page-1)/10)*10+1;
			int start=(Page-1)*perPage+1;
			

			
			ResultSet rs=dbc.executeQuery();
			if(rs.last())
			searchTopicNum=rs.getRow();
			if(start>searchTopicNum)
				return searchResult;
			rs.absolute(start);
			int i=0;
			
			
			do
				{
					

					
					ForumTopic theTopic=new ForumTopic();
					
					theTopic.setLockTopic(rs.getInt(1));
					theTopic.setForumID(rs.getInt(2));
					theTopic.setRootID(rs.getInt(3));
					theTopic.setAnnounceID(rs.getInt(4));
					theTopic.setBody(rs.getString(5));
					theTopic.setExpression(rs.getString(6));	
					theTopic.setTopic(rs.getString(7));
					theTopic.setUserName(rs.getString(8));
					theTopic.setChildNum(rs.getInt(9));
					theTopic.setHits(rs.getInt(10));
					theTopic.setDateAndTime(rs.getString(11));


					/*theTopic.setParentID(rs.getInt(2));
					
					
					
					theTopic.setUserEmail(rs.getString(6));
					
					
					
					
					theTopic.setLength(rs.getInt(11));
					
					theTopic.setLayer(rs.getInt(13));
					theTopic.setOrders(rs.getInt(14));
					theTopic.setIsBest(rs.getInt(15));
					theTopic.setUserIP(rs.getString(16));
					
					theTopic.setTimes(rs.getInt(18));
					
					theTopic.setSignFlag(rs.getInt(20));
					theTopic.setEmailFlag(rs.getInt(21));
					theTopic.setIsTop(rs.getInt(22));
					theTopic.setIsVote(rs.getInt(23));*/
					searchResult.add(theTopic);
					i++;
					if(i==perPage)
					break;
				}
			while(rs.next());
			dbc.close();
			


		}
		catch(Exception e){
			throw e;
		}

	 return searchResult;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -