日期:2014-05-18 浏览次数:20666 次
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <%@page import="org.apache.lucene.search.*,ly.SearchIndex"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>搜索结果</title> <style type="text/css"> <!-- .STYLE1 { font-family: "仿宋_GB2312"; font-size: xx-large; font-color: #666666 } --> </style> </head> <body> <p class="STYLE1">搜索结果: </p><hr> <% String keyword = new String(request.getParameter("searchquery").getBytes("ISO-8859-1"),"gb2312"); Hits hits = (new SearchIndex()).search(keyword); int length = hits.length(); int currentPage,recordPerPage=13; if (request.getParameter("currentPage") == null) currentPage = 1; else currentPage = Integer.valueOf(request.getParameter("currentPage")); for (int i = (currentPage-1)*recordPerPage;i < length && i < currentPage*recordPerPage;i++) { out.println("<a href=\""+hits.doc(i).get("URL")+"\">"+hits.doc(i).get("title")+i+"</a><br>"); String bodyContain = hits.doc(i).get("body").substring(0,1023); String tempkeyword = null; if (keyword.charAt(0) >= 65 && keyword.charAt(0) <= 90) { tempkeyword = keyword.replace(keyword.charAt(0),(char)(keyword.charAt(0)+32)); bodyContain = bodyContain.replaceAll(tempkeyword , "<font color=#E50060>" + tempkeyword + "</font>"); } else if (keyword.charAt(0) >= 97 && keyword.charAt(0) <= 122) { tempkeyword = keyword.replace(keyword.charAt(0),(char)(keyword.charAt(0)-32)); bodyContain = bodyContain.replaceAll(tempkeyword , "<font color=#E50060>" + tempkeyword + "</font>"); } bodyContain = bodyContain.replaceAll(keyword , "<font color=#E50060>" + keyword + "</font>"); out.println(i+"<br>"); out.println(bodyContain); out.println(i+"<br>"); out.println("<br/><br/>"); } out.println("<br/>"); out.println("there is " + length + " result matched"); %> <hr> 共有<%=length%>个记录 <%if (length%recordPerPage == 0) out.println(length/recordPerPage); else out.println(length/recordPerPage + 1);%>页 每页显示<%=recordPerPage%>个记录 <br/> <%if(currentPage == 1){ out.print(" 首页 上一页"); }else{ %> <a href="searchindex.jsp?currentPage=<%=1%>">首页</a> <a href="searchindex.jsp?currentPage=<%=currentPage-1%>">上一页</a> <%}%> <%if(currentPage == length){ out.print("下一页 尾页"); }else{ %> <A HREF="searchindex.jsp?currentPage=<%=currentPage+1%>">下一页</A> <A HREF="searchindex.jsp?currentPage=<%=length%>">尾页</A> <%}%> </body> </html>
out.println(i+"