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. java框架之Spring(4)-Spring整合Hibernate和Struts2

    准备 导包 Struts2 导入 Struts2 zip 包解压目录下 'apps/struts-blank.war' 中所有 jar 包,如下: asm-3.3.jar asm-commons-3. ...

  2. cocos2d JS-(JavaScript) 冒泡排序

    思想: 比较相邻的元素.如果第一个比第二个大,就交换他们两个. 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对.在这一点,最后的元素应该会是最大的数. 针对所有的元素重复以上的步骤,除了最 ...

  3. python 爬虫-1

    买了本书在自学,我也不知道自己能学到什么地步,反正不用这个找工作,纯属爱好,有可能之后就会放弃 233333333.... 先来一个特别简单点的:将百度搜索主页  扒下来,并保存到一个文件里面 fir ...

  4. 《linux就该这么学》开课,linux之路新开始

    今天开课第一天,虽然不会有实实在在的干货知识,只要是了解一下linux和认证.所以我也简单说一下我的linux之路 linux我是无意接触到的,因为工作,我接触的服务器较多,但是都是linux系统,记 ...

  5. Qt 的坐标系统

    QWidget *q = , Qt::WindowStaysOnTopHint); q->setWindowTitle(QObject::tr("父窗口widget")); ...

  6. sql 身份证计算年龄和性别

    IdentityNumber 是身份证号 年龄: ,), GETDATE()) / 365.25) as '推荐人年龄', 15位的身份证计算年龄: case when b.IdentityNumbe ...

  7. 去掉vim的BELL提示音

    title: date: 2017-11-09 15:07:08 tags: vim categories: 开发工具 --- 在vi/vim中使用 :set noeb 意思是noerrorbells ...

  8. POJ 2154 color (polya + 欧拉优化)

    Beads of N colors are connected together into a circular necklace of N beads (N<=1000000000). You ...

  9. Java正则表达式草稿程序*2

    1.成绩统计. 输入文件input.txt: 张三 语文12 数学31 英语11 李四 语文22 数学22 英语22 王五 语文33 数学33 英语33 期待输出output.txt: 张三 语文12 ...

  10. Centos下安装cassandra

    一.环境准备 环境 Centos6.5  .安装有Java JDK(https://www.cnblogs.com/wt645631686/p/8267239.html这篇文章里有安装JDK1.8的教 ...