Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-1050 Add segmentDir to WebGraph

Markus Jelsmad2d88461705f
diff --git a/conf/log4j.properties b/conf/log4j.properties
index 9ec5d451b..54ad346f3 100644
--- a/conf/log4j.properties
+++ b/conf/log4j.properties
@@ -27,6 +27,11 @@ log4j.logger.org.apache.nutch.indexer.solr.SolrWriter=INFO,cmdstdout
log4j.logger.org.apache.nutch.indexer.solr.SolrDeleteDuplicates=INFO,cmdstdout
log4j.logger.org.apache.nutch.indexer.solr.SolrClean=INFO,cmdstdout
log4j.logger.org.apache.nutch.scoring.webgraph.WebGraph=INFO,cmdstdout
+log4j.logger.org.apache.nutch.scoring.webgraph.LinkRank=INFO,cmdstdout
+log4j.logger.org.apache.nutch.scoring.webgraph.Loops=INFO,cmdstdout
+log4j.logger.org.apache.nutch.scoring.webgraph.ScoreUpdater=INFO,cmdstdout
+log4j.logger.org.apache.nutch.parse.ParserChecker=INFO,cmdstdout
+log4j.logger.org.apache.nutch.indexer.IndexingFiltersChecker=INFO,cmdstdout
log4j.logger.org.apache.nutch=INFO
log4j.logger.org.apache.hadoop=WARN
diff --git a/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java b/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java
index 0137d310b..e430510a3 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/LinkRank.java
@@ -538,7 +538,7 @@ public class LinkRank
+ (this.dampingFactor * totalInlinkScore);
LOG.info(url + ": score: " + linkRankScore + " num inlinks: "
- + numInlinks + " iteration: " + itNum + "\n");
+ + numInlinks + " iteration: " + itNum);
// store the score in a temporary NodeDb
Node outNode = (Node)WritableUtils.clone(node, conf);
diff --git a/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java b/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java
index 89fd52e38..b185c9436 100644
--- a/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java
+++ b/src/java/org/apache/nutch/scoring/webgraph/WebGraph.java
@@ -38,6 +38,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
@@ -61,6 +62,7 @@ import org.apache.nutch.net.URLNormalizers;
import org.apache.nutch.parse.Outlink;
import org.apache.nutch.parse.ParseData;
import org.apache.nutch.util.FSUtils;
+import org.apache.nutch.util.HadoopFSUtil;
import org.apache.nutch.util.LockUtil;
import org.apache.nutch.util.NutchConfiguration;
import org.apache.nutch.util.NutchJob;
@@ -617,26 +619,44 @@ public class WebGraph
"the web graph database to use").create("webgraphdb");
Option segOpts = OptionBuilder.withArgName("segment").hasArgs().withDescription(
"the segment(s) to use").create("segment");
+ Option segDirOpts = OptionBuilder.withArgName("segmentDir").hasArgs().withDescription(
+ "the segment directory to use").create("segmentDir");
options.addOption(helpOpts);
options.addOption(webGraphDbOpts);
options.addOption(segOpts);
+ options.addOption(segDirOpts);
CommandLineParser parser = new GnuParser();
try {
CommandLine line = parser.parse(options, args);
if (line.hasOption("help") || !line.hasOption("webgraphdb")
- || !line.hasOption("segment")) {
+ || (!line.hasOption("segment") && !line.hasOption("segmentDir"))
+) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("WebGraph", options);
return -1;
}
String webGraphDb = line.getOptionValue("webgraphdb");
- String[] segments = line.getOptionValues("segment");
- Path[] segPaths = new Path[segments.length];
- for (int i = 0; i < segments.length; i++) {
- segPaths[i] = new Path(segments[i]);
+
+ Path[] segPaths = null;
+
+ // Handle segment option
+ if (line.hasOption("segment")) {
+ String[] segments = line.getOptionValues("segment");
+ segPaths = new Path[segments.length];
+ for (int i = 0; i < segments.length; i++) {
+ segPaths[i] = new Path(segments[i]);
+ }
+ }
+
+ // Handle segmentDir option
+ if (line.hasOption("segmentDir")) {
+ Path dir = new Path(line.getOptionValue("segmentDir"));
+ FileSystem fs = dir.getFileSystem(getConf());
+ FileStatus[] fstats = fs.listStatus(dir, HadoopFSUtil.getPassDirectoriesFilter(fs));
+ segPaths = HadoopFSUtil.getPaths(fstats);
}
createWebGraph(new Path(webGraphDb), segPaths);