2012-01-30 4 views
0

MongoDB mapReduce에서 패턴 일치를 수행하려고합니다. 나는 db의 트윗 소스를 mapreducing하고있다. 그리고 2 번과 7 사이MongoDB MapReduce 맵 함수에서 replace() 대체

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 

유일한 차이점처럼 반복 결과를 얻는 것은 HREF에서 ".COM /"대 ".COM"입니다. 지도 기능에서 패턴 일치를 원하지만 컴파일 오류가 발생합니다. 나는 번역의 층에서 길을 잃어 가고 있을지도 모른다.

PHP ==> Mongo ==> javascript.

다음은이를 테스트하는 가장 쉬운 방법은 쉘에서 M/R을 실행하는 것입니다, 결과는 일반적으로

(
    [assertion] => couldn't compile code for: _map 
    [assertionCode] => 13598 
    [errmsg] => db assertion failure 
    [ok] => 0 
) 

답변

1

내 코드 블록

$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)); 

입니다. 이것은 쉘이 잘못된 구문을 식별 할 수있는 컴파일 b/c를 도와줍니다.

"인간 편집"기술을 사용하는 경우 다음과 같이 잘못되었습니다.

s = s.replace(/\/\"/i,"/""); 

당신은 /" 탈출하고 /로 대체된다? "/""을 살펴보십시오. 이중 따옴표가 너무 많습니다.

관련 문제