Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = Code((u'function() {\n'
- u' var langs = {};\n'
- u' langs[this.language] = 1;\n'
- u' var authors = {};\n'
- u' authors[this.author] = 1;\n'
- u' var count_followers = 0;\n'
- u' var count_mentions = {};\n'
- u' if ("twitter" in this.extra_info) {\n' # Twitter-specific things
- u' if (this.extra_info.twitter.count_followers == null) {\n'
- u' count_followers = 180;\n' # this is the average number of Twitter followers
- u' } else {\n'
- u' count_followers = this.extra_info.twitter.count_followers;\n'
- u' }\n'
- u' if ("mentions" in this.extra_info.twitter) {\n'
- u' for (var i in this.extra_info.twitter.mentions) {\n'
- u' var screen_name = this.extra_info.twitter.mentions[i];\n'
- u' count_mentions[screen_name] = 1;\n'
- u' }\n'
- u' }\n'
- u' }\n'
- u' var search_terms = [%s];\n' # Count search terms separately
- u' if (this.st_matches) {\n'
- u' var match_st = false;\n'
- u' for (var st in search_terms) {\n'
- u' for (var st_match in this.st_matches) {\n'
- u' if (st == st_match) {\n'
- u' match_st = true;\n'
- u' break;\n'
- u' }\n'
- u' }\n'
- u' }\n'
- u' if (match_st) {\n'
- u' emit(null,\n'
- u' {"count_blog_inlinks": this.blog_inlinks_count,\n'
- u' "count_microblog_inlinks": this.microblog_inlinks_count,\n'
- u' "count_postings_l": langs,\n'
- u' "count_postings": 1,\n'
- u' "count_followers": count_followers,\n'
- u' "authors": authors,\n'
- u' "count_mentions": count_mentions});\n'
- u' }\n'
- u' this.st_matches.forEach(function(st) {\n'
- u' emit(st,\n'
- u' {"count_blog_inlinks": this.blog_inlinks_count,\n'
- u' "count_microblog_inlinks": this.microblog_inlinks_count,\n'
- u' "count_postings_l": langs,\n'
- u' "count_postings": 1,\n'
- u' "count_followers": count_followers,\n'
- u' "authors": authors,\n'
- u' "count_mentions": count_mentions});\n'
- u' });\n'
- u' }\n'
- u'}' % search_term_js).encode(u'utf-8'))
- r = Code(u'function(st, values) {\n'
- u' var count_blog_inlinks = 0;\n'
- u' var count_microblog_inlinks = 0;\n'
- u' var count_postings_l = {};\n'
- u' var count_postings = 0;\n'
- u' var count_followers = 0;\n'
- u' var authors = {};\n' # User name -> number of postings written
- u' var count_mentions = {};\n' # User name -> number of @-mentions
- u' for (var search_term in values) {\n'
- u' var item = values[search_term];\n'
- u' for (var lang in item.count_postings_l) {\n'
- u' if (! search_term) {\n'
- u' if (isNaN(count_postings_l[lang]))\n'
- u' count_postings_l[lang] = 0;\n'
- u' count_postings_l[lang] += item.count_postings_l[lang];\n'
- u' }\n'
- u' }\n'
- u' count_postings += item.count_postings;\n'
- u' count_followers += item.count_followers;\n'
- u' for (var key in item.authors) {\n'
- u' if (isNaN(authors[key]))\n'
- u' authors[key] = 0;\n'
- u' authors[key] += item.authors[key];\n'
- u' }\n'
- u' for (var key in item.count_mentions) {\n'
- u' if (isNaN(count_mentions[key]))\n'
- u' count_mentions[key] = 0;\n'
- u' count_mentions[key] += item.count_mentions[key];\n'
- u' }\n'
- u' if (item.count_blog_inlinks)\n'
- u' count_blog_inlinks += item.count_blog_inlinks;\n'
- u' if (item.count_microblog_inlinks)\n'
- u' count_microblog_inlinks += item.count_microblog_inlinks;\n'
- u' }\n'
- u' return {"count_blog_inlinks": count_blog_inlinks,\n'
- u' "count_microblog_inlinks": count_microblog_inlinks,\n'
- u' "count_postings_l": count_postings_l,\n'
- u' "count_postings": count_postings,\n'
- u' "count_followers": count_followers,\n'
- u' "authors": authors,\n'
- u' "count_mentions": count_mentions\n'
- u' };'
- u'}')
- result_coll = coll.map_reduce(m, r, query=spec)
Advertisement
Add Comment
Please, Sign In to add comment