Apache Nutch is an extensible and scalable web crawler
NUTCH-44 - Too many search results. Configurable limit on max number of search results returned. Thanks Emilijan Mirceski and Susam Pal.
Dennis Kubes20efa46b6600
diff --git a/CHANGES.txt b/CHANGES.txtindex dd8a5c831..9b89e4bb2 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -212,6 +212,9 @@ Unreleased changes (1.0-dev)76. NUTCH-611 - Upgrade Nutch to use Hadoop 0.16 (kubes)+77. NUTCH-44 - Too many search results, limits max results returned from a+ single search. (Emilijan Mirceski and Susam Pal via kubes)+Release 0.9 - 2007-04-021. Changed log4j confiquration to log to stdout on commandlinediff --git a/conf/nutch-default.xml b/conf/nutch-default.xmlindex 8121f1727..ecc10a41e 100644--- a/conf/nutch-default.xml+++ b/conf/nutch-default.xml@@ -811,6 +811,17 @@</description></property>+<property>+ <name>searcher.max.hits.per.page</name>+ <value>1000</value>+ <description> The maximum number of hits to show per page. -1 if+ unlimited. If the number of hits requested by the user (via+ hitsPerPage parameter in the query string) is more than the value+ specified in this property, then this value is assumed as the number+ of hits per page.+ </description>+</property>+<!-- URL normalizer properties --><property>diff --git a/src/java/org/apache/nutch/searcher/OpenSearchServlet.java b/src/java/org/apache/nutch/searcher/OpenSearchServlet.javaindex cfdd9e99c..4b1d11fc0 100644--- a/src/java/org/apache/nutch/searcher/OpenSearchServlet.java+++ b/src/java/org/apache/nutch/searcher/OpenSearchServlet.java@@ -45,6 +45,7 @@ import javax.xml.transform.stream.StreamResult;* Nutch-specific extensions. */public class OpenSearchServlet extends HttpServlet {private static final Map NS_MAP = new HashMap();+ private int MAX_HITS_PER_PAGE;static {NS_MAP.put("opensearch", "http://a9.com/-/spec/opensearchrss/1.0/");@@ -67,6 +68,7 @@ public class OpenSearchServlet extends HttpServlet {} catch (IOException e) {throw new ServletException(e);}+ MAX_HITS_PER_PAGE = conf.getInt("searcher.max.hits.per.page", -1);}public void doGet(HttpServletRequest request, HttpServletResponse response)@@ -95,6 +97,8 @@ public class OpenSearchServlet extends HttpServlet {String hitsString = request.getParameter("hitsPerPage");if (hitsString != null)hitsPerPage = Integer.parseInt(hitsString);+ if(MAX_HITS_PER_PAGE > 0 && hitsPerPage > MAX_HITS_PER_PAGE)+ hitsPerPage = MAX_HITS_PER_PAGE;String sort = request.getParameter("sort");boolean reverse =diff --git a/src/web/jsp/search.jsp b/src/web/jsp/search.jspindex e74fdb3ee..1760d1452 100644--- a/src/web/jsp/search.jsp+++ b/src/web/jsp/search.jsp@@ -39,6 +39,11 @@*/private int HITS_TO_CLUSTER;+ /**+ * Maximum hits per page to be displayed.+ */+ private int MAX_HITS_PER_PAGE;+/*** An instance of the clustering extension, if available.*/@@ -57,8 +62,8 @@final ServletContext application = getServletContext();nutchConf = NutchConfiguration.get(application);-- HITS_TO_CLUSTER = nutchConf.getInt("extension.clustering.hits-to-cluster", 100);+ HITS_TO_CLUSTER = nutchConf.getInt("extension.clustering.hits-to-cluster", 100);+ MAX_HITS_PER_PAGE = nutchConf.getInt("searcher.max.hits.per.page", -1);try {clusterer = new OnlineClustererFactory(nutchConf).getOnlineClusterer();@@ -105,6 +110,8 @@String hitsString = request.getParameter("hitsPerPage");if (hitsString != null)hitsPerPage = Integer.parseInt(hitsString);+ if(MAX_HITS_PER_PAGE > 0 && hitsPerPage > MAX_HITS_PER_PAGE)+ hitsPerPage = MAX_HITS_PER_PAGE;int hitsPerSite = 2; // max hits per siteString hitsPerSiteString = request.getParameter("hitsPerSite");