MapReduce的倒排索引
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的倒排索引的更多相关文章
- 利用MapReduce实现倒排索引
这里来学习的是利用MapReduce的分布式编程模型来实现简单的倒排索引. 首先什么是倒排索引? 倒排索引是文档检索中最常用的数据结构,被广泛地应用于全文搜索引擎. 它主要是用来存储某个单词(或词组) ...
- MapReduce实例-倒排索引
环境: Hadoop1.x,CentOS6.5,三台虚拟机搭建的模拟分布式环境 数据:任意数量.格式的文本文件(我用的四个.java代码文件) 方案目标: 根据提供的文本文件,提取出每个单词在哪个文件 ...
- mapreduce (三) MapReduce实现倒排索引(二)
hadoop api http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/mapreduce/Reducer.html 改变一下需求: ...
- MapReduce实战--倒排索引
本文地址:http://www.cnblogs.com/archimedes/p/mapreduce-inverted-index.html,转载请注明源地址. 1.倒排索引简介 倒排索引(Inver ...
- Hadoop实战-MapReduce之倒排索引(八)
倒排索引 (就是key和Value对调的显示结果) 一.需求:下面是用户播放音乐记录,统计歌曲被哪些用户播放过 tom LittleApple jack YesterdayO ...
- MapReduce实现倒排索引(类似协同过滤)
一.问题背景 倒排索引其实就是出现次数越多,那么权重越大,不过我国有凤巢....zf为啥不管,总局回应推广是不是广告有争议... eclipse里ctrl+t找接口或者抽象类的实现类,看看都有啥方法, ...
- mapreduce (五) MapReduce实现倒排索引 修改版 combiner是把同一个机器上的多个map的结果先聚合一次
(总感觉上一篇的实现有问题)http://www.cnblogs.com/i80386/p/3444726.html combiner是把同一个机器上的多个map的结果先聚合一次现重新实现一个: 思路 ...
- mapreduce (二) MapReduce实现倒排索引(一) combiner是把同一个机器上的多个map的结果先聚合一次
1 思路:0.txt MapReduce is simple1.txt MapReduce is powerfull is simple2.txt Hello MapReduce bye MapRed ...
- 使用MapReduce实现一些经典的案例
在工作中,很多时候都是用hive或pig来自动化执行mr统计,但是我们不能忘记原始的mr.本文记录了一些通过mr来完成的经典的案例,有倒排索引.数据去重等,需要掌握. 一.使用mapreduce实现倒 ...
随机推荐
- bugfree3.0.1-BUG解决方案修改
该篇内容来自文档“masterBugFree2.pdf”,记录在这里. 1.如何将解决方案改为中文 在\Bugfree\Lang\ZH_CN_UTF-8 \_COMMON.php 文件中做如下修改/* ...
- Redis入门到高可用(十七)—— 持久化开发运维常见问题
1.fork操作 2.子进程开销和优化 3.AOF阻塞
- python中的单例
使用__new__ 因为一个类每一次实例化的时候,都会走它的__new__方法.所以我们可以使用__new__来控制实例的创建过程,代码如下: class Single: instance = Non ...
- JAVA:IDEA安装、创建项目、tomcat配置、maven配置(1)
一.安装 JDK安装自行百度,IDEA安装: IDEA安装包下载:https://www.jetbrains.com/idea/download/ 安装过程一路默认,需要选择的就勾选 .java之类的 ...
- JavaScript获取及判断文件类型
一.获取文件后缀 <input type="file" name="addvedio" accept="video/*"/>注: ...
- 解救小哈——dfs深搜
问题描述: 小哈去玩迷宫,结果迷路了,小哼去救小哈.迷宫由n行m列的单元格组成(n和m都小于等于50),每个单元格要么是空地,要么是障碍物. 问题:帮小哼找到一条从迷宫的起点通往小哈所在位置的最短路径 ...
- Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4
Failure to transfer org.apache.maven.plugins:maven-surefire-plugin:pom:2.12.4 from https://repo.mave ...
- 0005-20180422-自动化第六章-python基础学习笔记
day6 内容回顾: 1. 变量 2. 条件 3. while循环 4. 数据类型 - int - bit_length - bool - True/False - str - upper - low ...
- vue-cli 2.92版本 server
一.引包 const axios = require('axios'); const express = require('express'); const apiRoutes = express.R ...
- Why Choose MB SD C5 with Engineer Software
MB SD C5 with engineer software performed good and now is released. Unlike the old clone C5 which us ...