我正在尝试进行模式匹配并替换我的MongoDB mapReduce。我在map中减少了推文的来源。并获得重复的结果,如
1 - web has 38867
2 - <a href="http://www.tweetdeck.com" rel="nofollow">TweetDeck</a> has 23873
3 - <a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a> has 10696
4 - <a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a> has 9562
5 - <a href="http://twitter.com/#!/download/iphone" rel="nofollow">Twitter for iPhone</a> has 6818
6 - <a href="http://www.echofon.com/" rel="nofollow">Echofon</a> has 5869
7 - <a href="http://www.tweetdeck.com/" rel="nofollow">TweetDeck</a> has 5497
#2和#7之间的唯一区别是href中的“.com /”vs“.com”。我想在我的map函数中进行模式匹配,但是我遇到了编译错误。我可能会在翻译层面迷失方向。
PHP ==&gt; Mongo ==&gt;的JavaScript。
这是我的代码块
$map = 'function() {
if (!this.source) {
return;
}
s = this.source;
s = s.replace(/\/\"/i,"/"");
emit(s,1);
}';
$reduce = "function(previous, current) {
var count = 0;
for (index in current) {
count += current[index];
}
return count;
}";
$mapFunc = new MongoCode($map);
$reduceFunc = new MongoCode($reduce);
$collectionOutName = 'mrTweetSource';
$mr = $db->command(array(
'mapreduce' => 'tweet',
'map' => $mapFunc,
'reduce' => $reduceFunc,
'out'=>$collectionOutName));
结果是
(
[assertion] => couldn't compile code for: _map
[assertionCode] => 13598
[errmsg] => db assertion failure
[ok] => 0
)
答案 0 :(得分:1)
通常,最简单的测试方法就是从shell运行M / R.这将有助于编译b / c shell可以识别错误的语法。
如果我使用“人类编译”技能,则以下内容看起来不对。
s = s.replace(/\/\"/i,"/"");
您正在转发/"
并将其替换为/
?看看"/""
,这似乎是一个太多的双引号。