倒排索引解题思路


应用背景:对网页,文档进行合理的存储。构建合理的索引


数据源:
"mapreduce is simple , this is test case" (来自1.html)
"hello mapreduce ,hello world, hello mapreduce of inversedIndex,the athor is daidai"(来自2.html)


期望结果:某个单词在某个文档中出现的次数
(mapreduce,1.html:1;2.html:2)
 (is,1.html:2;2.html:1)


map任务:统计某个单词在某个文档中出现的了一次,通过combine任务来统计某个单词在某个文档中出现的总次数
所以我们期望的map结果如下:、
(mapreduce:1.html,1)
(is:1.html,1)
(is:1.html,1)
(mapreduce:2.html,1)
(mapreduce:2.html,1)
(is:2.html,1)


通过combine程序我们完成词频统计部分,得到结果
(mapreduce,1.html:1)
(is,1.html:2)
(mapreduce,2.html:2)
(is,2.html:1)


通过洗牌后,得到结果、
(mapreduce,(1.html:1),(2.html:2))
(is,(1.html:2);(2.html:1))
reduce任务无需特别处理直接统计结果:
(mapreduce,1.html:1;2.html:2)
(is,1.html:2;2.html:1)

相关内容