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

📄 searchall.jsp

📁 bbs系统源码有简单的bbs功能 论坛:http://www.mycodes.net/bbs
💻 JSP
字号:
<%@ page language="java" contentType="text/html;charset=UTF-8" session="true" errorPage="err.jsp" %><%@
page import = "org.apache.lucene.analysis.*
	, org.apache.lucene.analysis.cjk.*
	, org.apache.lucene.document.*
	, org.apache.lucene.search.Query
	, org.apache.lucene.search.Hits
	, org.apache.lucene.search.highlight.*
	"
%><%@ include file="./GVinc/gvImport.jsp" %><%
String keys= ParamUtils.getStringParameter(request, "keys", "").trim();
keys=com.gamvan.net.URL.urlDecoder(keys,"UTF-8");
keys=com.gamvan.tools.Gb.toUTF8(keys);
int iPage = ParamUtils.getIntParameter(request,"iPage",1);
%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=clubTitle%> - 全文检索</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META content=<%=clubMeta%> name=keywords>
<link href="./GVimgs/favicon.ico" rel="Bookmark"> 
<link rel="icon" href="./GVimgs/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="./GVimgs/favicon.ico" type="image/x-icon" />
<STYLE type="text/css" media="screen">@import url(./GVinc/GamVanClubStyle.css);</STYLE>
</head>
<body><DIV id="div_body">
<DIV id="waitDiv" style="LEFT: 40%; VISIBILITY: hidden; POSITION: absolute; TOP: 40%; TEXT-ALIGN: center">
<TABLE cellPadding=6 border=0>
<TBODY><TR><TD align=middle>
<IMG  src="GVimgs/loading.gif" alt="请稍候..." width="30" height="30">
<BR>
<FONT color="red">数据载入中,请稍候...</FONT></TD></TR></TBODY></TABLE></DIV>
<IFRAME id=hiddenframe style="DISPLAY: none" src="about:blank" width=0  height=0></IFRAME>
<script language="javascript" type="text/javascript" src="GVscript/GVtopCode.js"></script>
<script language="javascript" type="text/javascript" src="GVscriptInc/topBar.js"></script>
<script language="javascript" type="text/javascript">
	gv_showWait('waitDiv', 1);
	prtie2('<%=clubTitle%> - 社区搜索');
</script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
<%=com.gamvan.club.ClubHtmlConst.gamvan_menu("全文检索")%>
</DIV>
<DIV class="line"></DIV>
<DIV class="list_tab">
	<table border="0" cellpadding="1" cellspacing="1">
	<form name="Gfroms" method="get" action="searchAll.jsp"  onSubmit="javascript:postMsg();"><tr><td>
	<img src="GVimgs/search/gamvanlogo.gif" align="absmiddle">
	</td><td><input name="keys" type="text" id="keys" size="50" maxlength="50" value="<%=keys%>">
	</td></tr><tr><td align="center">(多个关键字用空格分开)
	</td><td>
	<input name="gvSubmit" type="submit" class="btn" id="gvSubmit2" value=" 全文检索 "/>
	</td></tr></form></table>
</DIV>	
<%
com.gamvan.club.search.ClubSearch cs = new com.gamvan.club.search.ClubSearch(request.getRealPath(""));
/*
csc.searchCfg();
String clubIndexPath = csc.getClubIndexPath();
Searcher searcher = new IndexSearcher(clubIndexPath); //索引目录
Analyzer analyzer = new CJKAnalyzer(); 
Query query = null;
Hits hits = null; 
String[] fields = {"topic","content"}; 
query = MultiFieldQueryParser.parse(keys, fields, analyzer);
hits = searcher.search(query);
*/
Date startTime = new Date(); //开始时间,用于计算搜索耗时
String[] fields = {"topic","content"};
Hits hits;
Query query;
try{
	hits  = cs.clubSearchHits(fields, keys);
	query = cs.getQuery();
}catch(Exception e){
	//out.print(e.toString());
	out.print(prtCenter("系统正在维护,请稍候访问...","",2));
	out.print(Gfoot());
	out.close();
	if(true)return;
}
if(hits!=null){
	int totalrows = cs.getTotalrows();
	int listrows = 30; //每页显示行数
	int startrows = 0; //显示记录集的起始行
	int maxrows = listrows; //当前页最大行数
	/* 翻页滤错开始 */
	if(listrows>totalrows){
		listrows = totalrows;
	}
	if(iPage>1){
		startrows = (listrows * (iPage-1));
		maxrows = startrows + listrows;
	}
	if(maxrows > totalrows){
		maxrows = totalrows;
	}
	/* 翻页滤错结束 */
	Date endTime = new Date();
	out.print("<DIV class=\"line\"></DIV>");
	out.print("<DIV class=\"list_tab_0\">GamVan一下找到相关主题约<strong> ");
	out.print(totalrows);
	out.print(" </strong>篇,检索耗时 <strong>");
	out.print((endTime.getTime() - startTime.getTime()) / 1000.0);
	out.print("</strong> 秒</DIV>");
	QueryScorer scorer = new QueryScorer(query);
	SimpleHTMLFormatter sf = new SimpleHTMLFormatter("","");
	Highlighter highlighter = new Highlighter(sf, scorer);
	Fragmenter fm = new SimpleFragmenter(30);
	highlighter.setTextFragmenter(fm);
	String content = "";
	String topic = "";
	String lighterContent = "";
	String lighterTopic = "";
	TokenStream stream = null;
	for (int i = startrows; i < maxrows; i++) {
		%>
		<DIV class="line"></DIV>
		<DIV class="list_search">
		<%
		Document doc = hits.doc(i);     
		topic = EncodeString.htmlEncoder(doc.get("topic").trim()); 
		content = EncodeString.htmlEncoder(doc.get("content").trim()); 
		//stream = new CJKAnalyzer().tokenStream("topic",new StringReader(topic));
		//lighterTopic = highlighter.getBestFragment(stream, topic);
		stream = new CJKAnalyzer().tokenStream("content",new StringReader(content));
		lighterContent = highlighter.getBestFragments(stream, content,5,"...");
		//if(lighterTopic!=null){
			//topic = lighterTopic;
		//}
		if(lighterContent!=null){
			content = lighterContent;
		}
		out.print("<a href=\"clubPage.jsp?ccID=");
		out.print(doc.get("ccID"));
		out.print("&tID=");
		out.print(doc.get("topicID"));
		out.print("&reID=");
		out.print(doc.get("topicReID"));
		out.print("&ccStyle=1\"");
		out.print(" target=\"_blank\"><span style=\"font-size: 14PX; font-weight: bold;\">");
		out.print(topic);
		out.print("</span></a>&nbsp;&nbsp;&nbsp;&nbsp;");
		out.print(OutPrint.isDateHtml3(doc.get("topicAddTime"),"yyyy-MM-dd"));
		out.print("<br/><span style=\"color: #666666;\">");
		out.print(content);
		out.print("</span>");
	%></DIV><table width="200" border="0"><tr><td></td></tr></table><%
	topic = null;
	content = null;
	}%>
	<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
	<tr><td>
	<%=OutPrint.pageJump(totalrows,listrows, iPage, "searchAll.jsp?keys="+com.gamvan.net.URL.urlEncoder(keys, "UTF-8")+"&")%>
	</td></tr></table>
<%
}else{
		out.print("<DIV class=\"list_tab_1\">");
		out.print("<center>请输入关键字检索内容......</center>");
		out.print("</DIV><DIV class=\"line\"></DIV>");
}
%><%@ include file="GVinc/gvOnlineArea.jsp" %><%=Gfoot()%>
</DIV>
</body>
</html>

⌨️ 快捷键说明

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