Inverted index(Map Reduce)

Inverted index(Map Reduce)_第1张图片
image.png

Python Solution:

class WordCount:
    def mapper(self, key, line):
        # key我们可以当做是index,或者URL
        for word in line.split():
            yield word, key

    # @param key is from mapper
    # @param values is a set of value with the same key
    def reducer(self, key, values):
        # values 是一组index 或者 URL
        indexes = []
        for v in values:
            indexes.append(v)
        yield key, indexes

你可能感兴趣的:(Inverted index(Map Reduce))