Guest User

map/reduce function leading to an assertion failure in mongodb 1.6.x

a guest
Sep 6th, 2010
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.27 KB | None | 0 0
  1.     m = Code((u'function() {\n'
  2.              u'   var langs = {};\n'
  3.              u'   langs[this.language] = 1;\n'
  4.              u'   var authors = {};\n'
  5.              u'   authors[this.author] = 1;\n'
  6.              u'   var count_followers = 0;\n'
  7.              u'   var count_mentions = {};\n'
  8.              u'   if ("twitter" in this.extra_info) {\n'    # Twitter-specific things
  9.              u'      if (this.extra_info.twitter.count_followers == null) {\n'
  10.              u'         count_followers = 180;\n'           # this is the average number of Twitter followers
  11.              u'      } else {\n'
  12.              u'         count_followers = this.extra_info.twitter.count_followers;\n'
  13.              u'      }\n'
  14.              u'      if ("mentions" in this.extra_info.twitter) {\n'
  15.              u'         for (var i in this.extra_info.twitter.mentions) {\n'
  16.              u'            var screen_name = this.extra_info.twitter.mentions[i];\n'
  17.              u'            count_mentions[screen_name] = 1;\n'
  18.              u'         }\n'
  19.              u'      }\n'
  20.              u'   }\n'
  21.              u'   var search_terms = [%s];\n'               # Count search terms separately
  22.              u'   if (this.st_matches) {\n'
  23.              u'      var match_st = false;\n'
  24.              u'      for (var st in search_terms) {\n'
  25.              u'         for (var st_match in this.st_matches) {\n'
  26.              u'            if (st == st_match) {\n'
  27.              u'               match_st = true;\n'
  28.              u'               break;\n'
  29.              u'            }\n'
  30.              u'         }\n'
  31.              u'      }\n'
  32.              u'      if (match_st) {\n'
  33.              u'         emit(null,\n'
  34.              u'            {"count_blog_inlinks": this.blog_inlinks_count,\n'
  35.              u'             "count_microblog_inlinks": this.microblog_inlinks_count,\n'
  36.              u'             "count_postings_l": langs,\n'
  37.              u'             "count_postings": 1,\n'
  38.              u'             "count_followers": count_followers,\n'
  39.              u'             "authors": authors,\n'
  40.              u'             "count_mentions": count_mentions});\n'
  41.              u'      }\n'
  42.              u'      this.st_matches.forEach(function(st) {\n'
  43.              u'         emit(st,\n'
  44.              u'            {"count_blog_inlinks": this.blog_inlinks_count,\n'
  45.              u'             "count_microblog_inlinks": this.microblog_inlinks_count,\n'
  46.              u'             "count_postings_l": langs,\n'
  47.              u'             "count_postings": 1,\n'
  48.              u'             "count_followers": count_followers,\n'
  49.              u'             "authors": authors,\n'
  50.              u'             "count_mentions": count_mentions});\n'
  51.              u'      });\n'
  52.              u'   }\n'
  53.              u'}' % search_term_js).encode(u'utf-8'))
  54.     r = Code(u'function(st, values) {\n'
  55.              u'   var count_blog_inlinks = 0;\n'
  56.              u'   var count_microblog_inlinks = 0;\n'
  57.              u'   var count_postings_l = {};\n'
  58.              u'   var count_postings = 0;\n'
  59.              u'   var count_followers = 0;\n'
  60.              u'   var authors = {};\n'            # User name -> number of postings written
  61.              u'   var count_mentions = {};\n'     # User name -> number of @-mentions
  62.              u'   for (var search_term in values) {\n'
  63.              u'      var item = values[search_term];\n'
  64.              u'      for (var lang in item.count_postings_l) {\n'
  65.              u'         if (! search_term) {\n'
  66.              u'            if (isNaN(count_postings_l[lang]))\n'
  67.              u'               count_postings_l[lang] = 0;\n'
  68.              u'            count_postings_l[lang] += item.count_postings_l[lang];\n'
  69.              u'         }\n'
  70.              u'      }\n'
  71.              u'      count_postings += item.count_postings;\n'
  72.              u'      count_followers += item.count_followers;\n'
  73.              u'      for (var key in item.authors) {\n'
  74.              u'         if (isNaN(authors[key]))\n'
  75.              u'            authors[key] = 0;\n'
  76.              u'         authors[key] += item.authors[key];\n'
  77.              u'      }\n'
  78.              u'      for (var key in item.count_mentions) {\n'
  79.              u'         if (isNaN(count_mentions[key]))\n'
  80.              u'            count_mentions[key] = 0;\n'
  81.              u'         count_mentions[key] += item.count_mentions[key];\n'
  82.              u'      }\n'
  83.              u'      if (item.count_blog_inlinks)\n'
  84.              u'         count_blog_inlinks += item.count_blog_inlinks;\n'
  85.              u'      if (item.count_microblog_inlinks)\n'
  86.              u'         count_microblog_inlinks += item.count_microblog_inlinks;\n'
  87.              u'   }\n'
  88.              u'   return {"count_blog_inlinks": count_blog_inlinks,\n'
  89.              u'           "count_microblog_inlinks": count_microblog_inlinks,\n'
  90.              u'           "count_postings_l": count_postings_l,\n'
  91.              u'           "count_postings": count_postings,\n'
  92.              u'           "count_followers": count_followers,\n'
  93.              u'           "authors": authors,\n'
  94.              u'           "count_mentions": count_mentions\n'
  95.              u'          };'
  96.              u'}')
  97.  
  98.     result_coll = coll.map_reduce(m, r, query=spec)
Advertisement
Add Comment
Please, Sign In to add comment