如何实现generate.max.count的参数处理
本篇文章为大家展示了如何实现generate.max.count的参数处理,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
对generate.max.count参数的处理在org.apache.nutch.crawl.Generator内部类Selector中
org.apache.nutch.crawl.Generator中相关变量声明情况
privateHashMap<String,int[]>hostCounts=newHashMap<String,int[]>(); privateintmaxCount;
内部类Selector的config方法中
maxCount=job.getInt(GENERATOR_MAX_COUNT,-1);
reduce方法中的处理
/*** 1、获取某一主机下的int[],如果为null,声明一个数组,放入map中,int数组第2个值+1; */ //1 int[]hostCount=hostCounts.get(hostordomain); if(hostCount==null){ hostCount=newint[]{1,0}; hostCounts.put(hostordomain,hostCount); } hostCount[1]++;//incrementhostCount //2、检查是否到了topN的数量,如果hostCount的第一个值大于limit //checkiftopNreached,selectnextsegmentifitis while(segCounts[hostCount[0]-1]>=limit//segCounts: &&hostCount[0]<maxNumSegments){ hostCount[0]++; hostCount[1]=0; } //reachedthelimitofallowedURLsperhost/domain //seeifwecanputitinthenextsegment? if(hostCount[1]>=maxCount){ if(hostCount[0]<maxNumSegments){ hostCount[0]++; hostCount[1]=0; }else{ if(hostCount[1]==maxCount+1 &&LOG.isInfoEnabled()){ LOG.info("Hostordomain" +hostordomain +"hasmorethan" +maxCount +"URLsforall" +maxNumSegments +"segments.AdditionalURLswon'tbeincludedinthefetchlist."); } //skipthisentry continue; } } entry.segnum=newIntWritable(hostCount[0]); segCounts[hostCount[0]-1]++;
上述内容就是如何实现generate.max.count的参数处理,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注博信行业资讯频道。
版权声明
本文仅代表作者观点,不代表博信信息网立场。