Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-603 - Add more default url normalizations.

Dennis Kubes083b25cdbe41
diff --git a/CHANGES.txt b/CHANGES.txt
index f2b59dfc9..54066e8f5 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -208,6 +208,8 @@ Unreleased changes (1.0-dev)
74. NUTCH-605 - Change deprecated configuration methods for Hadoop (kubes)
+75. NUTCH-603 - Add more default url normalizations (kubes)
+
Release 0.9 - 2007-04-02
1. Changed log4j confiquration to log to stdout on commandline
diff --git a/conf/regex-normalize.xml.template b/conf/regex-normalize.xml.template
index ecd5221bf..5b82f6baa 100644
--- a/conf/regex-normalize.xml.template
+++ b/conf/regex-normalize.xml.template
@@ -23,16 +23,44 @@
<!-- WATCH OUT: an xml parser reads this file an ampersands must be
expanded to &amp; -->
-<!-- The following rules show how to strip out session IDs
- that are 32 characters long and have the parameter
- name of PHPSESSID. Order does matter! -->
+<!-- The following rules show how to strip out session IDs, default pages,
+ interpage anchors, etc. Order does matter! -->
<regex-normalize>
+
+<!-- removes session ids from urls (such as jsessionid and PHPSESSID) -->
<regex>
- <pattern>(\?|\&amp;|\&amp;amp;)PHPSESSID=[a-zA-Z0-9]{32}$</pattern>
- <substitution></substitution>
+ <pattern>([;_]?((?i)l|j|bv_)?((?i)sid|phpsessid|sessionid)=.*?)(\?|&amp;|#|$)</pattern>
+ <substitution>$4</substitution>
+</regex>
+
+<!-- changes default pages into standard for /index.html, etc. into /
+<regex>
+ <pattern>/((?i)index|default)\.((?i)js[pf]{1}?[afx]?|cgi|cfm|asp[x]?|[psx]?htm[l]?|php[3456]?)(\?|&amp;|#|$)</pattern>
+ <substitution>/$3</substitution>
+</regex> -->
+
+<!-- removes interpage href anchors such as site.com#location -->
+<regex>
+ <pattern>#.*?(\?|&amp;|$)</pattern>
+ <substitution>$1</substitution>
+</regex>
+
+<!-- cleans ?&amp;var=value into ?var=value -->
+<regex>
+ <pattern>\?&amp;</pattern>
+ <substitution>\?</substitution>
+</regex>
+
+<!-- cleans multiple sequential ampersands into a single ampersand -->
+<regex>
+ <pattern>&amp;{2,}</pattern>
+ <substitution>&amp;</substitution>
</regex>
+
+<!-- removes trailing ? -->
<regex>
- <pattern>(\?|\&amp;|\&amp;amp;)PHPSESSID=[a-zA-Z0-9]{32}(\&amp;|\&amp;amp;)(.*)</pattern>
- <substitution>$1$3</substitution>
+ <pattern>[\?&amp;\.]$</pattern>
+ <substitution></substitution>
</regex>
+
</regex-normalize>
diff --git a/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.test b/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.test
index 34fceda4b..54e392c15 100644
--- a/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.test
+++ b/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.test
@@ -1,11 +1,70 @@
-# test simple removal of session id
+# test simple removal of session id, keeping parameters before and after
http://foo.com/foo.php?PHPSESSID=cdc993a493e899bed04f4d0c8a462a03 http://foo.com/foo.php
-
-# test removal of session id, and keep parameters before
http://foo.com/foo.php?f=2&PHPSESSID=cdc993a493e899bed04f4d0c8a462a03 http://foo.com/foo.php?f=2
-
-# test removal of session id, and keep parameters after
http://foo.com/foo.php?f=2&PHPSESSID=cdc993a493e899bed04f4d0c8a462a03&q=3 http://foo.com/foo.php?f=2&q=3
-
-# test removal of session id, and keep parameters after
http://foo.com/foo.php?PHPSESSID=cdc993a493e899bed04f4d0c8a462a03&f=2 http://foo.com/foo.php?f=2
+
+# test removal of different session ids including removal of ; in jsessionid
+http://www.foo.com/foo.php?Bv_SessionID=fassassddsajkl http://www.foo.com/foo.php
+http://www.foo.com/foo.php?Bv_SessionID=fassassddsajkl&x=y http://www.foo.com/foo.php?x=y
+http://www.foo.com/foo.html;jsessionid=1E6FEC0D14D044541DD84D2D013D29ED http://www.foo.com/foo.html
+http://www.foo.com/foo.html?param=1&another=2;jsessionid=1E6FEC0D14D044541DD84D2D013D29ED http://www.foo.com/foo.html?param=1&another=2
+http://www.foo.com/foo.html;jsessionid=1E6FEC0D14D044541DD84D2D013D29ED?param=1&another=2 http://www.foo.com/foo.html?param=1&another=2
+http://www.foo.com/foo.php?&x=1&sid=xyz&something=1 http://www.foo.com/foo.php?x=1&something=1
+
+# test removal default pages
+http://www.foo.com/home/index.html http://www.foo.com/home/
+http://www.foo.com/index.html http://www.foo.com/
+http://www.foo.com/index.htm http://www.foo.com/
+http://www.foo.com/index.asp http://www.foo.com/
+http://www.foo.com/index.aspx http://www.foo.com/
+http://www.foo.com/index.php http://www.foo.com/
+http://www.foo.com/index.php3 http://www.foo.com/
+http://www.foo.com/default.html http://www.foo.com/
+http://www.foo.com/default.htm http://www.foo.com/
+http://www.foo.com/default.asp http://www.foo.com/
+http://www.foo.com/default.aspx http://www.foo.com/
+http://www.foo.com/default.php http://www.foo.com/
+http://www.foo.com/default.php3 http://www.foo.com/
+http://www.foo.com/something.php3 http://www.foo.com/something.php3
+http://www.foo.com/something.html http://www.foo.com/something.html
+http://www.foo.com/something.asp http://www.foo.com/something.asp
+http://www.foo.com/index.phtml http://www.foo.com/
+http://www.foo.com/index.cfm http://www.foo.com/
+http://www.foo.com/index.cgi http://www.foo.com/
+http://www.foo.com/index.HTML http://www.foo.com/
+http://www.foo.com/index.Htm http://www.foo.com/
+http://www.foo.com/index.ASP http://www.foo.com/
+http://www.foo.com/index.jsp http://www.foo.com/
+http://www.foo.com/index.jsf http://www.foo.com/
+http://www.foo.com/index.jspx http://www.foo.com/
+http://www.foo.com/index.jspfx http://www.foo.com/index.jspfx
+http://www.foo.com/index.jspa http://www.foo.com/
+http://www.foo.com/index.jsps http://www.foo.com/index.jsps
+http://www.foo.com/index.aspX http://www.foo.com/
+http://www.foo.com/index.PhP http://www.foo.com/
+http://www.foo.com/index.PhP4 http://www.foo.com/
+http://www.foo.com/default.HTml http://www.foo.com/
+http://www.foo.com/default.HTm http://www.foo.com/
+http://www.foo.com/default.ASp http://www.foo.com/
+http://www.foo.com/default.AspX http://www.foo.com/
+http://www.foo.com/default.PHP http://www.foo.com/
+http://www.foo.com/default.PHP3 http://www.foo.com/
+http://www.foo.com/index.phtml http://www.foo.com/
+http://www.foo.com/index.cfm http://www.foo.com/
+http://www.foo.com/index.cgi http://www.foo.com/
+
+# ensure keeping non-default pages
+http://www.foo.com/foo.php3 http://www.foo.com/foo.php3
+http://www.foo.com/foo.html http://www.foo.com/foo.html
+http://www.foo.com/foo.asp http://www.foo.com/foo.asp
+
+# test removal of interpage anchors and keeping query string
+http://www.foo.com/foo.html#something http://www.foo.com/foo.html
+http://www.foo.com/foo.html#something?x=y http://www.foo.com/foo.html?x=y
+
+# test general cleaning of bad urls
+http://www.foo.com/foo.html?&x=y http://www.foo.com/foo.html?x=y
+http://www.foo.com/foo.html?x=y&&&z=a http://www.foo.com/foo.html?x=y&z=a
+http://www.foo.com/foo.html? http://www.foo.com/foo.html
+
diff --git a/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.xml b/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.xml
index 40e802ff6..8c68b5095 100644
--- a/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.xml
+++ b/src/plugin/urlnormalizer-regex/sample/regex-normalize-default.xml
@@ -7,17 +7,46 @@
<!-- WATCH OUT: an xml parser reads this file an ampersands must be
expanded to &amp; -->
-<!-- The following rules show how to strip out session IDs
- that are 32 characters long and have the parameter
- name of PHPSESSID. Order does matter! -->
+<!-- The following rules show how to strip out session IDs, default pages,
+ interpage anchors, etc. Order does matter! -->
<regex-normalize>
+
+<!-- removes session ids from urls (such as jsessionid and PHPSESSID) -->
<regex>
- <pattern>(\?|\&amp;|\&amp;amp;)PHPSESSID=[a-zA-Z0-9]{32}$</pattern>
- <substitution></substitution>
+ <pattern>([;_]?((?i)l|j|bv_)?((?i)sid|phpsessid|sessionid)=.*?)(\?|&amp;|#|$)</pattern>
+ <substitution>$4</substitution>
+</regex>
+
+<!-- changes default pages into standard for /index.html, etc. into / -->
+<!-- these are commented in the default file but uncommented here for testing -->
+<regex>
+ <pattern>/((?i)index|default)\.((?i)js[pf]{1}?[afx]?|cgi|cfm|asp[x]?|[psx]?htm[l]?|php[3456]?)(\?|&amp;|#|$)</pattern>
+ <substitution>/$3</substitution>
+</regex>
+
+<!-- removes interpage href anchors such as site.com#location -->
+<regex>
+ <pattern>#.*?(\?|&amp;|$)</pattern>
+ <substitution>$1</substitution>
+</regex>
+
+<!-- cleans ?&var=value into ?var=value -->
+<regex>
+ <pattern>\?&amp;</pattern>
+ <substitution>\?</substitution>
+</regex>
+
+<!-- cleans multiple sequential ampersands into a single ampersand -->
+<regex>
+ <pattern>&amp;{2,}</pattern>
+ <substitution>&amp;</substitution>
</regex>
+
+<!-- removes trailing ?, ampersands, . -->
<regex>
- <pattern>(\?|\&amp;|\&amp;amp;)PHPSESSID=[a-zA-Z0-9]{32}(\&amp;|\&amp;amp;)(.*)</pattern>
- <substitution>$1$3</substitution>
+ <pattern>[\?&amp;\.]$</pattern>
+ <substitution></substitution>
</regex>
+
</regex-normalize>
diff --git a/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java b/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java
index be5f5c523..4a0dafdf7 100644
--- a/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java
+++ b/src/plugin/urlnormalizer-regex/src/test/org/apache/nutch/net/urlnormalizer/regex/TestRegexURLNormalizer.java
@@ -91,8 +91,11 @@ public class TestRegexURLNormalizer extends TestCase {
private void normalizeTest(NormalizedURL[] urls, String scope) throws Exception {
for (int i = 0; i < urls.length; i++) {
- assertEquals(urls[i].expectedURL,
- normalizer.normalize(urls[i].url, scope));
+ String url = urls[i].url;
+ String normalized = normalizer.normalize(urls[i].url, scope);
+ String expected = urls[i].expectedURL;
+ LOG.info("scope: " + scope + " url: " + url + " | normalized: " + normalized + " | expected: " + expected);
+ assertEquals(urls[i].expectedURL, normalized);
}
}