Skip to content

Apache Lucene open-source search software

added logging

cmarschner2d3e3954ac00
diff --git a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/KnownPathsFilter.java b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/KnownPathsFilter.java
index 251f27b6755..f6c18f1f25c 100644
--- a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/KnownPathsFilter.java
+++ b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/KnownPathsFilter.java
@@ -55,6 +55,9 @@
package de.lanlab.larm.fetcher;
import java.net.*;
+import java.util.ArrayList;
+import java.io.*;
+import de.lanlab.larm.util.*;
/**
* this can be considered a hack
@@ -68,14 +71,12 @@ public class KnownPathsFilter extends Filter implements MessageListener
String[] pathsToFilter =
{
- "/robots.txt"
+ "/robots.txt",
+ "/lmu-32321800/"
};
- String[] hostFilter =
- {
- "www.nm.informatik.uni-muenchen.de",
- "cgi.cip.informatik.uni-muenchen.de"
- };
+ ArrayList hosts = new ArrayList();
+ Object[] hostsToFilter = null;
String[] filesToFilter =
{
@@ -93,18 +94,27 @@ public class KnownPathsFilter extends Filter implements MessageListener
int pathLength;
int fileLength;
int hostLength;
-
+ SimpleLogger log;
/**
* Constructor for the KnownPathsFilter object
*/
- public KnownPathsFilter()
+ public KnownPathsFilter(SimpleLogger log)
{
pathLength = pathsToFilter.length;
+ this.log = log;
fileLength = filesToFilter.length;
- hostLength = hostFilter.length;
}
+ /**
+ * add "forbidden" host name
+ * note: this has no effect after the filter has been added to the message handler
+ * @param hostname
+ */
+ public void addHostToFilter(String hostname)
+ {
+ this.hosts.add(hostname);
+ }
/**
* Description of the Method
@@ -114,34 +124,47 @@ public class KnownPathsFilter extends Filter implements MessageListener
*/
public Message handleRequest(Message message)
{
- URL url = ((URLMessage)message).getUrl();
- String file = url.getFile();
- String host = url.getHost();
- int i;
- for (i = 0; i < pathLength; i++)
+ try
{
- if (file.startsWith(pathsToFilter[i]))
+ URL url = new URL(((URLMessage)message).getNormalizedURLString());
+ String file = url.getFile();
+ String host = url.getHost();
+ int i;
+ for (i = 0; i < pathLength; i++)
{
- filtered++;
- return null;
+ if (file.startsWith(pathsToFilter[i]))
+ {
+ filtered++;
+ //log.log("KnownPathsFilter: filtered file '" + url + "' - file starts with " + pathsToFilter[i]);
+ log.log(message.toString());
+ return null;
+ }
}
- }
- for (i = 0; i < fileLength; i++)
- {
- if (file.endsWith(filesToFilter[i]))
+ for (i = 0; i < fileLength; i++)
{
- filtered++;
- return null;
+ if (file.endsWith(filesToFilter[i]))
+ {
+ filtered++;
+ //log.log("KnownPathsFilter: filtered file '" + url + "' - file ends with " + filesToFilter[i]);
+ log.log(message.toString());
+ return null;
+ }
}
- }
- for (i = 0; i<hostLength; i++)
- {
- if(hostFilter[i].equals(host))
+ for (i = 0; i<hostLength; i++)
{
- filtered++;
- return null;
+ if(hostsToFilter[i].equals(host))
+ {
+ filtered++;
+ //log.log("KnownPathsFilter: filtered file '" + url + "' - host equals " + host);
+ log.log(message.toString());
+ return null;
+ }
}
}
+ catch(MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
return message;
}
@@ -154,5 +177,7 @@ public class KnownPathsFilter extends Filter implements MessageListener
public void notifyAddedToMessageHandler(MessageHandler handler)
{
this.messageHandler = messageHandler;
+ this.hostsToFilter = hosts.toArray();
+ this.hostLength = hostsToFilter.length;
}
}
diff --git a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLLengthFilter.java b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLLengthFilter.java
index cf5ebeb59d6..bbe7e3acc12 100644
--- a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLLengthFilter.java
+++ b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLLengthFilter.java
@@ -54,6 +54,8 @@
package de.lanlab.larm.fetcher;
+import de.lanlab.larm.util.*;
+
/**
* kills URLs longer than X characters. Used to prevent endless loops where
* the page contains the current URL + some extension
@@ -80,13 +82,24 @@ public class URLLengthFilter extends Filter implements MessageListener
int maxLength;
+// URLLengthFilter()
+// {
+// maxLength = 0;
+// }
+ SimpleLogger log;
/**
* Constructor for the URLLengthFilter object
*
* @param maxLength max length of the _total_ URL (protocol+host+port+path)
*/
- public URLLengthFilter(int maxLength)
+ public URLLengthFilter(int maxLength, SimpleLogger log)
+ {
+ this.maxLength = maxLength;
+ this.log = log;
+ }
+
+ public void setMaxLength(int maxLength)
{
this.maxLength = maxLength;
}
@@ -105,6 +118,8 @@ public class URLLengthFilter extends Filter implements MessageListener
if (file != null && file.length() > maxLength) // path + query
{
filtered++;
+ //log.log("URLLengthFilter: URL " + m.getUrl() + " exceeds maxLength " + this.maxLength);
+ log.log(message.toString());
return null;
}
return message;
diff --git a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLVisitedFilter.java b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLVisitedFilter.java
index 728f6dcb528..9ad480e054b 100644
--- a/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLVisitedFilter.java
+++ b/sandbox/contributions/webcrawler-LARM/src/de/lanlab/larm/fetcher/URLVisitedFilter.java
@@ -95,11 +95,13 @@ public class URLVisitedFilter extends Filter implements MessageListener
*
* @param initialHashCapacity Description of the Parameter
*/
- public URLVisitedFilter(int initialHashCapacity)
+ public URLVisitedFilter(SimpleLogger log, int initialHashCapacity)
{
urlHash = new HashSet(initialHashCapacity);
//urlVector = new Vector(initialHashCapacity);
+ this.log = log;
}
+ SimpleLogger log;
/**
@@ -113,7 +115,7 @@ public class URLVisitedFilter extends Filter implements MessageListener
- /**
+ /**q
* @param message Description of the Parameter
* @return Description of the Return Value
*/
@@ -126,8 +128,10 @@ public class URLVisitedFilter extends Filter implements MessageListener
String urlString = urlMessage.getNormalizedURLString();
if (urlHash.contains(urlString))
{
- //System.out.println("URLVisitedFilter: " + urlString + " already present.");
+ //log.log("URLVisitedFilter: " + urlString + " already present.");
+ log.log(message.toString());
filtered++;
+
return null;
}
else