anchor.diff:                          <td>Summary</td>
                   </tr>
   <%
  -                if ((startindex + maxpage) > hits.length()) {
  -                        thispage = hits.length() - startindex;      // set the max index to maxpage or last
  +                if ((startindex + maxpage) > hits.totalHits) {
  +                        thispage = hits.totalHits - startindex;      // set the max index to maxpage or last
                   }                                                   // actual search result whichever is less
   
                   for (int i = startindex; i < (thispage + startindex); i++) {  // for each element
   %>
                   <tr>
   <%
  -                        Document doc = hits.doc(i);                    //get the next document 
  +                        Document doc = searcher.doc(hits.scoreDocs[i].doc);                    //get the next document 
                           String doctitle = doc.get("title");            //get its title
                           String url = doc.get("path");                  //get its path field
                           if (url != null && url.startsWith("../webapps/")) { // strip off ../webapps prefix if present
  
positive.code:         String indexName = indexLocation;       //local copy of the configuration variable
          IndexSearcher searcher = null;          //the searcher used to open/search the index
          Query query = null;                     //the Query created by the QueryParser
          Hits hits = null;                       //the search results
          int startindex = 0;                     //the first index displayed on this page
          int maxpage    = 50;                    //the maximum items displayed on this page
          String queryString = null;              //the query entered in the previous page
          String startVal    = null;              //string version of startindex
          String maxresults  = null;              //string version of maxpage
          int thispage = 0;                       //used for the for/next either maxpage or
                                                  //hits.length() - startindex - whichever is
                                                  //less
  
          try {
            searcher = new IndexSearcher(indexName);      //create an indexSearcher for our page
                                                          //NOTE: this operation is slow for large
                                                          //indices (much slower than the search itself)
                                                          //so you might want to keep an IndexSearcher 
  
negative.code:                                                                       //query string so you get the 
                                                                        //treatment
  
                  Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);           //construct our usual analyzer
                  try {
                          QueryParser qp = new QueryParser("contents", analyzer);
                          query = qp.parse(queryString); //parse the 
  