MapReduce的倒排索引

索引:

什么是索引:索引(Index)是帮助数据库高效获取数据的数据结构。索引是在基于数据库表创建的,它包含一个表中某些列的值以及记录对应的地址,并且把这些值存储在一个数据结构中。最常见的就是使用哈希表、B+树作为索引。

索引的具体分析:https ://blog.csdn.net/meiLin_Ya/article/details/80854232

用代码说事,先来看看我的数据吧:

包com.huhu.day05;

import java.io.IOException;

导入org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner; import com.huhu.day04.ProgenyCount; 公共类InvertedIndex扩展ToolRunner实现工具{ 私人配置conf; 公共静态类MyMapper扩展Mapper <LongWritable,文本,文本,文本> { 私人FileSplit拆分;
private Text va = new Text(); @覆盖
保护无效设置(Mapper <LongWritable,Text,Text,Text> .Context上下文)
抛出IOException,InterruptedException {
split =(FileSplit)context.getInputSplit();
} @覆盖
protected void map(LongWritable key,Text value,Context context)throws IOException,InterruptedException {
String [] line = value.toString()。split(“”);
通信System.err.println(线);
String filename = split.getPath()。getName();
for(String s:line){
va.set(“fileName:”+ filename +“:”+ key.get()+“\ t索引位置:”+ value.toString()。indexOf(s)+“\ t”);
context.write(new Text(“搜索词:”+ s +“\ r”),new Text(va));
} }
} 公共静态类MyReduce扩展Reducer <文本,文本,文本,文本> { @覆盖
保护无效设置(上下文上下文)抛出IOException,InterruptedException {
} @覆盖
protected void reduce(Text key,Iterable <Text> values,Context context)
抛出IOException,InterruptedException {
StringBuffer sb = new StringBuffer();
for(Text v:values){
sb.append(v.toString());
}
context.write(new Text(key),new Text(sb.toString()));
} @覆盖
保护无效清理(上下文上下文)抛出IOException,InterruptedException {
}
} 公共静态无效的主要(字符串[]参数)抛出异常{
InvertedIndex t = new InvertedIndex();
配置conf = t.getConf();
String [] other = new GenericOptionsParser(conf,args).getRemainingArgs();
if(other.length!= 2){
System.err.println(“number is fail”);
}
int run = ToolRunner.run(conf,t,args);
System.exit(运行);
} @覆盖
public Configuration getConf(){
if(conf!= null){
返回conf;
}
返回新的配置();
} @覆盖
public void setConf(Configuration arg0){ } @覆盖
公共诠释运行(字符串[]其他)抛出异常{
配置con = getConf();
Job job = Job.getInstance(con);
job.setJarByClass(ProgenyCount.class);
job.setMapperClass(MyMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(Text.class); //默认分区
// job.setPartitionerClass(HashPartitioner.class); job.setReducerClass(MyReduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class); FileInputFormat.addInputPath(job,new Path(“hdfs:// ry-hadoop1:8020 / in / day05 / InvertedIndex”));
Path path = new Path(“hdfs:// ry-hadoop1:8020 / out / day05.txt”);
FileSystem fs = FileSystem.get(getConf());
if(fs.exists(path)){
fs.delete(path,true);
}
FileOutputFormat.setOutputPath(job,path); 返回job.waitForCompletion(true)?0:1;
} }

索引很重要:

详情:https ://blog.csdn.net/meiLin_Ya/article/details/80854232

MapReduce的倒排索引的更多相关文章

  1. 利用MapReduce实现倒排索引

    这里来学习的是利用MapReduce的分布式编程模型来实现简单的倒排索引. 首先什么是倒排索引? 倒排索引是文档检索中最常用的数据结构,被广泛地应用于全文搜索引擎. 它主要是用来存储某个单词(或词组) ...

  2. MapReduce实例-倒排索引

    环境: Hadoop1.x,CentOS6.5,三台虚拟机搭建的模拟分布式环境 数据:任意数量.格式的文本文件(我用的四个.java代码文件) 方案目标: 根据提供的文本文件,提取出每个单词在哪个文件 ...

  3. mapreduce (三) MapReduce实现倒排索引(二)

    hadoop api http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/mapreduce/Reducer.html 改变一下需求: ...

  4. MapReduce实战--倒排索引

    本文地址:http://www.cnblogs.com/archimedes/p/mapreduce-inverted-index.html,转载请注明源地址. 1.倒排索引简介 倒排索引(Inver ...

  5. Hadoop实战-MapReduce之倒排索引(八)

    倒排索引 (就是key和Value对调的显示结果) 一.需求:下面是用户播放音乐记录,统计歌曲被哪些用户播放过 tom        LittleApple jack       YesterdayO ...

  6. MapReduce实现倒排索引(类似协同过滤)

    一.问题背景 倒排索引其实就是出现次数越多,那么权重越大,不过我国有凤巢....zf为啥不管,总局回应推广是不是广告有争议... eclipse里ctrl+t找接口或者抽象类的实现类,看看都有啥方法, ...

  7. mapreduce (五) MapReduce实现倒排索引 修改版 combiner是把同一个机器上的多个map的结果先聚合一次

    (总感觉上一篇的实现有问题)http://www.cnblogs.com/i80386/p/3444726.html combiner是把同一个机器上的多个map的结果先聚合一次现重新实现一个: 思路 ...

  8. mapreduce (二) MapReduce实现倒排索引(一) combiner是把同一个机器上的多个map的结果先聚合一次

    1 思路:0.txt MapReduce is simple1.txt MapReduce is powerfull is simple2.txt Hello MapReduce bye MapRed ...

  9. 使用MapReduce实现一些经典的案例

    在工作中,很多时候都是用hive或pig来自动化执行mr统计,但是我们不能忘记原始的mr.本文记录了一些通过mr来完成的经典的案例,有倒排索引.数据去重等,需要掌握. 一.使用mapreduce实现倒 ...

随机推荐

  1. SharePoint开启错误提示

    1,打开80下面的Web.config文件2,CallStack="true" 和 <customErrors mode="Off" /> < ...

  2. 本地资源_Asset

    数据 using System.Collections.Generic; using UnityEngine; public enum Enum_Test { A, B, C, } [System.S ...

  3. C#ImageList和ListView的使用

    一.ImageList  ImageList组件,又称为图片存储组件,它主要用于存储图片资源,然后在控件上显示出来,这样就简化了对图片的管理.ImageList组件的主要属性是Images,它包含关联 ...

  4. python多线程学习一

    本文希望达到的目标: 多线程的基本认识 多线程编程的模块和类的使用 Cpython的全局解释器锁GIL 一.多线程的基本认识 多线程编程的目的:并行处理子任务,大幅度地提升整个任务的效率. 线程就是运 ...

  5. wingIDE Pro6 破解教程

    亲测wingIDE pro6.0.6-1激活成功 算号器下载 激活的时候选择第三项 打开算号器,获得license id 把算号器里的license id输入到第一步的输入框里 continue得到r ...

  6. Applet程序组件与AJAX技术

    Applet 定义 Applet是一种运行于Web客户端环境下的Java程序组件. 工作原理 Applet以代码的形式嵌入Web页面中,用标签<applet></applet> ...

  7. java4/9 异常处理

  8. LeetCode #001# Two Sum(js描述)

    索引 思路1:暴力搜索 思路2:聪明一点的搜索 思路3:利用HashMap巧解 问题描述:https://leetcode.com/problems/two-sum/ 思路1:暴力搜索 一个很自然的想 ...

  9. Codeforces Round #505 (Div 1 + Div 2 Combined) Solution

    从这里开始 题目列表 瞎扯 Problem A Doggo Recoloring Problem B Weakened Common Divisor Problem C Plasticine zebr ...

  10. log4net架构、配置、使用

    架构说明 架构说明 上图是官方文档的提供的代码组织. Log4net的核心组件有: Logger, Appender, Filter, Layout, Object Render, Logger介绍 ...