各位,请问个问题,
我用lucene做索引,做了分页,但是每页的内容都没有变,URL中的page是在改变,各位给我分析下,究竟是什么原因
这是我的源码,请帮我看看:package com.tt;
import java.io.IOException;import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.Query;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.document.Document;
import org.mira.lucene.analysis.IK_CAnalyzer;
public class GoodsSearch{
static IndexSearcher createSearch(){
try{
return new IndexSearcher("C:\\Program Files\\Apache Software Foundation\\Tomcat 6.0\\index1");
}catch (IOException ex)
{
//ex.printStackTrace();
return null;
}
}
public static IndexSearcher search = createSearch();
public static int perPage = 10; //每页显示的商品数量
public static int before = 5; //当前页码之前的页码个数
public static int after = 5; //当前页面之后的页码个数
public int pages = 0; //总的页面数
public int curPage = 1;
public int startPage = 1;  //分页显示的第一个页码
public int endPage = 0; //分页显示的最后一个页码
public int len = 0; //总共商品数量
public Hits hits = null; //
public GoodsSearch(int curPag,String keywords)throws ParseException,IOException
{
MultiFieldQueryParser parser = new MultiFieldQueryParser(new String[]{"title","site"}, new IK_CAnalyzer());
Query query;
query = parser.parse(keywords);
hits = search.search(query);
len = hits.length();
pages = len/perPage + 1;
if (curPag > pages || curPag < 1)
{
curPage = 1;
}else{
curPage = curPag;
}
if (curPage >before)
{
startPage = curPage -before;
}
endPage = curPage + after;
if (endPage > pages)
{
endPage = pages;
}
}
}下面是部分的JSP语言。<?xml version="1.0" encoding="utf-8" ?>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page import = "org.apache.lucene.analysis.Analyzer,
java.io.IOException,
org.apache.lucene.document.Document,
org.apache.lucene.index.CorruptIndexException, 
org.mira.lucene.analysis.IK_CAnalyzer,
org.apache.lucene.search.IndexSearcher,
org.apache.lucene.queryParser.*,
org.apache.lucene.search.Query,
org.apache.lucene.search.Hits,
com.tt.GoodsSearch,
java.lang.Exception,
java.lang.NumberFormatException,
java.lang.Integer,
java.util.Date"%>
<%
String keywords = request.getParameter("keywords").trim();
String pageStr = request.getParameter(keywords);
Integer pageInteger = null;
int curPage = 1;
try{
pageInteger = Integer.parseInt(pageStr);
curPage = pageInteger.intValue();
}catch(NumberFormatException ex)
{
curPage = 1;
}
%>
<head>
<!-- meta tags begin -->
<!-- vital meta tags -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<meta name="Description" content="summerBreeze is a CSS driven and XHML 1.1 valid template featuring a special tabbed main navigation and wise use of the white spaces." />
<meta name="Keywords" content="summerbreeze, summer breeze, free css template, valid xhtml template, open source template, free xhtml template, stamatis kritikos" />
<!-- defining stylesheet, rss feed and shortcut icon to use -->
<link rel="stylesheet" href="c:/tt/media/base.css" type="text/css" media="screen" /><!-- one style sheet to style them all, valid with no errors -->
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" /><!-- our custom little favicon -->
<!-- secondary meta tags -->
<meta http-equiv="Content-Language" content="English" />
<meta name="Author" content="Stamatis Kritikos" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="imagetoolbar" content="no" /><!-- get rid of IE's image toolbar -->
<!-- meta tags end -->
</head>
<body>
<!-- BEGIN search -->
<div id="search">
<form method="get" action="http://localhost:8080/search/search.jsp">
<div>
<label for="mainsearchbox">商品搜索</label> 
<!--<input type="hidden" name="ps" value="10" />-->
<input type="hidden" name="page" value="1" />
<input id="mainsearchbox" type="text" name="keywords" value="" class="tbox" />
<input type="submit" value="Search" name="搜索" />
</div>
</form>
<ul>
<li><a href="#">Advanced Search</a></li>
<li><a href="#">Sitemap</a></li>
</ul>
</div>
<div id="center">
<div id="cc">
<!--{%block content%}{%endblock%}-->
<% if (!keywords.equals(""))
{
GoodsSearch search = new GoodsSearch(curPage, keywords);
%>
<p>您正在搜索商品 <%=keywords%>, 总共找到 <%=search.len%> 件 </p>
<p>------------------------------------------------------------------------------------</p>
<table width="690" border="0" cellpadding="0" cellspacing="0">
<%
int end = (search.curPage)*(GoodsSearch.perPage);
int start = (search.curPage-1)*(GoodsSearch.perPage);
if (end > search.len)
end = search.len;
if (start > end)
start = 0;
  for (int i = start; i < end; i++)
{
  Document doc = null;
  try{
doc = search.hits.doc(i);
  }catch(IOException ex)
  {
ex.printStackTrace();
  }
%>
  <tr>
    <td width="140" rowspan="6" valign="top"><img src="<%=doc.get("imgurl") %>" onmousewheel="return bbimg(this)" onload="javascript:if(this.width>140){this.resized=true;this.style.width=140;}"/></td>
    <td width="9" rowspan="6" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="316" rowspan="3" valign="top"><%=doc.get("title") %></td>
    <td width="10" rowspan="6" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="141" rowspan="6" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
    <td width="10" height="15">&nbsp;</td>
    <td width="13">&nbsp;</td>
    <td width="38">&nbsp;</td>
    <td width="13">&nbsp;</td>
  </tr>
  <tr>
    <td rowspan="2" valign="top"><a href="http://localhost/seComt/?tabl=<%=doc.get("tabl") %>&gid=<%=doc.get("gid") %>" target="_blank">共有 <%=doc.get("comments") %> 条评论</a>  站点  <%=doc.get("site") %></td>
    <td height="14">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
<%}%><!--end of for-->
</table>
<p id="pagenator">
<%if(search.curPage != 1){%><a href="http://localhost:8080/search/search.jsp?page=<%=search.curPage-1%>&keywords=<%=keywords%>">上一页 </a><%}%>
<%int iend = search.endPage+1;
int i = search.startPage;%>
<%for(; i<iend; i++){%>
<a href="http://localhost:8080/search/search.jsp?page=<%=i%>&keywords=<%=keywords%>"><%=i%></a>
<%}%><!--end of for-->
<%if(search.curPage != search.pages){%>
<a href="http://localhost:8080/search/search.jsp?page=<%=search.curPage+1%>&keywords=<%=keywords %>">下一页</a><%} %></p>
<%}%><!-- endof if (!keywords.equals(""))-->
</div><!-- END cc -->
</div><!-- END center -->
<!-- BEGIN right column -->
<div id="right">
<div id="rc">
<!--{%block ad%}{%endblock%}-->
</div><!-- END rc -->
</div><!-- END right -->
<!-- clear any float commands left -->
<br class="clear" />
</body>
</html>

解决方案 »

  1.   

    Lucene这是专门用来分页的类包吗?  没用过  学习了!
      

  2.   

    ><a href="http://localhost:8080/search/search.jsp?page=<%=search.curPage-1%>&keywords=<%=keywords%>">上一页 </a><%
    <a href="http://localhost:8080/search/search.jsp?page=<%=search.curPage+1%>&keywords=<%=keywords %>">下一页</a><%} %></
    看一下源文件里page=的值就知道有没有分页了啊
    再调试一下不就行了?? curPage;
      

  3.   

    pager-taglib.jar
    专门用来分页的jar包,可能对你有帮助
      

  4.   

    Lucene是大名鼎鼎的建立索引的程序,呵呵,
      

  5.   

    String keywords = request.getParameter("keywords").trim();
    String pageStr = request.getParameter(“page”);
    Integer pageInteger = null;
    int curPage = 1;
    try{
    pageInteger = Integer.parseInt(pageStr);
    curPage = pageInteger.intValue();
    }catch(NumberFormatException ex)
    {    
        curPage = 1;
    }