-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueryMapper.java
More file actions
33 lines (30 loc) · 1.2 KB
/
Copy pathQueryMapper.java
File metadata and controls
33 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class QueryMapper extends Mapper<LongWritable,Text,Text,Text> {
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException,InterruptedException
{
Configuration conf = context.getConfiguration();
String keyWordsString = conf.get("KEYWORDS");
String[] keyWords = keyWordsString.split(" ");
Set<String> keyWordSet = new HashSet<>(Arrays.asList(keyWords));
String[] input = value.toString().split("\\{");
String term = input[0].trim();
StringBuilder sb = new StringBuilder();
if (keyWordSet.contains(term)) {
String[] items = input[1].substring(0, input[1].length() - 1).split(", ");
for (String item: items) {
String fileName = item.split("=")[0];
sb.append(fileName + " ");
}
context.write(new Text(term), new Text(sb.toString().trim()));
}
}
}