From: <bi...@us...> - 2009-03-03 18:20:21
|
Revision: 2687 http://archive-access.svn.sourceforge.net/archive-access/?rev=2687&view=rev Author: binzino Date: 2009-03-03 18:20:14 +0000 (Tue, 03 Mar 2009) Log Message: ----------- Fixed handling of start and end of search results so that we detect "paging off the end" and return an empty result set rather than an exception. Modified Paths: -------------- trunk/archive-access/projects/nutchwax/archive/src/java/org/archive/nutchwax/OpenSearchServlet.java Modified: trunk/archive-access/projects/nutchwax/archive/src/java/org/archive/nutchwax/OpenSearchServlet.java =================================================================== --- trunk/archive-access/projects/nutchwax/archive/src/java/org/archive/nutchwax/OpenSearchServlet.java 2009-02-28 01:26:25 UTC (rev 2686) +++ trunk/archive-access/projects/nutchwax/archive/src/java/org/archive/nutchwax/OpenSearchServlet.java 2009-03-03 18:20:14 UTC (rev 2687) @@ -162,18 +162,30 @@ responseTime = System.nanoTime( ) - responseTime; - // generate xml results - int end = (int)Math.min(hits.getLength(), start + hitsPerPage); - int length = end-start; + // The 'end' is usually just the end of the current page + // (start+hitsPerPage); but if we are on the last page + // of de-duped results, then the end is hits.getLength(). + int end = Math.min( hits.getLength( ), start + hitsPerPage ); - Hit[] show = hits.getHits(start, end-start); - HitDetails[] details = bean.getDetails(show); - Summary[] summaries = bean.getSummary(details, query); + // The length is usually just (end-start), unless the start + // position is past the end of the results -- which is common when + // de-duping. The user could easily jump past the true end of the + // de-dup'd results. If the start is past the end, we use a + // length of '0' to produce an empty results page. + int length = Math.max( end-start, 0 ); + // Usually, the total results is the total number of non-de-duped + // results. Howerver, if we are on last page of de-duped results, + // then we know our de-dup'd total is hits.getLength(). + long totalResults = hits.getLength( ) < (start+hitsPerPage) ? hits.getLength( ) : hits.getTotal( ); + + Hit[] show = hits.getHits(start, length ); + HitDetails[] details = bean.getDetails(show); + Summary[] summaries = bean.getSummary(details, query); + String requestUrl = request.getRequestURL().toString(); String base = requestUrl.substring(0, requestUrl.lastIndexOf('/')); - try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); @@ -197,8 +209,8 @@ +"&hitsPerDup="+hitsPerDup +params); - addNode(doc, channel, "opensearch", "totalResults", ""+hits.getTotal()); - addNode(doc, channel, "opensearch", "startIndex", ""+start); + addNode(doc, channel, "opensearch", "totalResults", ""+totalResults); + addNode(doc, channel, "opensearch", "startIndex", ""+start); addNode(doc, channel, "opensearch", "itemsPerPage", ""+hitsPerPage); addNode(doc, channel, "nutch", "query", queryString); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |