We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0141e00 commit 7550448Copy full SHA for 7550448
spark-demo/invertedIndex/src/main/scala/invertedIndex.scala
@@ -18,10 +18,11 @@ object InvertedIndex{
18
val cfg = new HierConf(args(0))
19
val inputfile = cfg.getString("inputfile")
20
val result = sc.textFile(inputfile)
21
- .map(x => x.split("\t"))
22
- .map(x => (x(0), x(1)))
23
- .map(x => x._2.split(" ").map(y => (y, x._1)))
24
- .flatMap(x => x)
+ .flatMap(x => {
+ val arr = x.split("\t")
+ val arr_words = arr(1).split(" ")
+ arr_words.map(y => (y, arr(0)))
25
+ })
26
.reduceByKey( (x, y) => x + "|" + y)
27
result.collect.foreach(println)
28
sc.stop()
0 commit comments