开发者

Possible to join text together by key in a Apache CouchDB reduce function?

Consider the approximated result from map function:

"key": "andy", "value" :  "Once upon a time",
"key": "andy", "value" :  "...",
"key": "andy", "value" :  "They all lived happily ever after.",

I would like to create a reduce function that generates:

"key":"andy", 
"value":"Once upon a time ... They all lived happily ever a开发者_JS百科fter."


A reduce function aggregates the values of the map function, but it has to be associative and commutative. If you use a simple concatenation as a reduce function, you may end up with 'They all lived happily ever after. Once upon a time ...', which is probably not what you want. I can't think of a reduce function that leads to 'Once upon a time ... They all lived happily ever after.' for sure. I guess you need to do part of the work on the client side. But you need information about the correct order of your text snippets. Your current view has no information about that. In a view, there is no order for values with the same key. You may need a composite key which, in addition to 'andy', stores information about the correct order.

Here are to links about reduce functions you may find useful:

http://damienkatz.net/2008/02/incremental_map.html

http://damienkatz.net/2008/02/incremental_map_1.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜