日期:2014-05-18  浏览次数:20731 次

求lucene分页例子,只要有帮助都给分
求lucene分页例子

------解决方案--------------------
帮顶
------解决方案--------------------
up
------解决方案--------------------
网上找的 看有帮助没


一、输入关键字的lucene.html
<html>
<body>
<form name= "form1 " method= "post " action= "search.jsp ">
请输入关键字: <input type= "text " name= "keyword ">
<input type= "submit " name= "Submit " value= "提交 ">
</form>
</body>
</html>
二、进行搜索和显示结果的search.jsp <%@ page contentType= "text/html; charset=gb2312 " %>
<%@ page import= "java.util.* " %>
<%@ page import= "java.text.SimpleDateFormat " %>
<%@ page import = "org.apache.lucene.analysis.standard.StandardAnalyzer " %>
<%@ page import= "org.apache.lucene.index.IndexReader " %>
<%@ page import= "org.apache.lucene.document.Document " %>
<%@ page import= "org.apache.lucene.search.IndexSearcher " %>
<%@ page import= "org.apache.lucene.search.Hits " %>
<%@ page import= "org.apache.lucene.search.Query " %>
<%@ page import= "page.Pagination " %> <%@ page import= "org.apache.lucene.queryParser.QueryParser " %>
<%@ page import = "org.apache.lucene.analysis.Analyzer " %>
<%

String queryString = request.getParameter( "keyword ");

if (queryString == null||queryString.length()==0){
out.println( "搜索关键字不能为空 ");

}else{
queryString=new String(queryString.getBytes( "ISO8859_1 "));
String indexPath=getServletContext().getRealPath( "/ ")+ "index ";
boolean error = false;
Document doc;

IndexSearcher searcher = null;
Query query = null;
Hits hits = null;

try {
searcher = new IndexSearcher(IndexReader.open(indexPath));
} catch (Exception e) {
out.print( "没有找到索引文件! ");
out.print(e.getMessage());
error = true;
}
if (error == false) {
Analyzer analyzer = new StandardAnalyzer();
try {
query = QueryParser.parse(queryString, "Article_name ", analyzer);
} catch (Exception e) {
out.print(e.getMessage());
error = true;

}
}
if (error == false && searcher != null) {

hits = searcher.search(query);
if (hits.length() == 0) {
out.print( "对不起!没有找到你所需要的资源. ");
error = true;
}
}
if (error == false && searcher != null) {
ou