继续向下看,第二个Job
.................... .................... .................... // read the subdirectories generated in the temp // output and turn them into segments List<Path> generatedSegments = new ArrayList<Path>(); //读取上个job生成的多个fetchlist的segment FileStatus[] status = fs.listStatus(tempDir); try { for (FileStatus stat : status) { Path subfetchlist = stat.getPath(); //过滤掉不是以fetchlist开头的文件 if (!subfetchlist.getName().startsWith("fetchlist-")) continue; // start a new partition job for this segment //一个partition Job 对segment Path newSeg = partitionSegment(fs, segments, subfetchlist, numLists); generatedSegments.add(newSeg); } } catch (Exception e) { LOG.warn("Generator: exception while partitioning segments, exiting ..."); fs.delete(tempDir, true); return null; } if (generatedSegments.size() == 0) { LOG.warn("Generator: 0 records selected for fetching, exiting ..."); LockUtil.removeLockFile(fs, lock); fs.delete(tempDir, true); return null; } .................... .................... ....................
// 这里主要是通过URLPartitioner来做的,具体是按哪一个来分类,是通用参数来配置的,这里有PARTITION_MODE_DOMAIN,PARTITION_MODE_IP
// 来配置,默认是按Url的hashCode来分。
private Path partitionSegment(FileSystem fs, Path segmentsDir, Path inputDir, int numLists) throws IOException { // invert again, partition by host/domain/IP, sort by url hash if (LOG.isInfoEnabled()) { LOG.info("Generator: Partitioning selected urls for politeness."); } //产生一个新的目录,以当前时间明明 Path segment = new Path(segmentsDir, generateSegmentName()); //在上面的目录下,再产生一个特定的crawl_generate目录 Path output = new Path(segment, CrawlDatum.GENERATE_DIR_NAME); LOG.info("Generator: segment: " + segment); NutchJob job = new NutchJob(getConf()); job.setJobName("generate: partition " + segment); job.setInt("partition.url.seed", new Random().nextInt()); FileInputFormat.addInputPath(job, inputDir); job.setInputFormat(SequenceFileInputFormat.class); job.setMapperClass(SelectorInverseMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(SelectorEntry.class); job.setPartitionerClass(URLPartitioner.class); job.setReducerClass(PartitionReducer.class); job.setNumReduceTasks(numLists); FileOutputFormat.setOutputPath(job, output); job.setOutputFormat(SequenceFileOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(CrawlDatum.class); job.setOutputKeyComparatorClass(HashComparator.class); JobClient.runJob(job); return segment; }
相关推荐
apache-nutch-2.3.1-src.tar.gz
nutch配置nutch-default.xml
apache-nutch-1.3 的源码包,需要的可以看下
外网不能访问,故上传,一方面自己备份,一方面也方便大家不能下载的痛苦,只有nutch的源码,没有依赖包,如果需要依赖包,请自行下载
nutch-param-setnutch-param-setnutch-param-setnutch-param-set
apache-nutch-2.3.1-src.tar ,网络爬虫的源码, 用ivy2管理, ant runtime 编译 apache-nutch-2.3.1-src.tar ,网络爬虫的源码, 用ivy2管理, ant runtime 编译
Nutch是一款刚刚诞生的完整的开源搜索引擎系统,可以结合数据库进行索引,能快速构建所需系统。Nutch 是基于Lucene的,Lucene为 Nutch 提供了文本索引和搜索的API,所以它使用Lucene作为索引和检索的模块。Nutch的...
Nutch 是一个开源Java 实现的搜索引擎。这里是它的安装包。
apache-nutch-1.6-src.tar.gz 来自APACHE官网,本人亲自测试可以使用。
nutch不用安装,是个应用程序,下载后为nutch-1.6.tar.gz,双击桌面上的cygwin快捷方式;执行以下命令: $ cd D:/Downloads/Soft $ tar zxvf nutch-1.0.tar.gz 在e盘下面出现nutch-0.9文件夹说明解压成功了.然后环境...
lucene+nutch搜索引擎光盘源码(1-8章),一次上传不了那么多所以分卷了。
Nutch 1.2 学习笔记,讲的比较清楚的文档
Nutch 是一个开源Java 实现的搜索引擎。它提供了我们运行自己的搜索引擎所需的全部工具。包括全文搜索和Web爬虫。包含nutch-1.5.1的源码
apache-nutch-1.4-bin.tar.gz.part2
学习nutch 源码解读 轻松入门 搭建自己的nutch搜索引擎
nutch1.6源码,直接从官网也可以下
nutch-1.0-dev.jar nutch devlope
apache-nutch-2.3-src.zip来自APACHE官方网站,亲自测试可以使用。
apache-nutch-1.4-bin.part2
apache-nutch-1.4-bin.part1