tags:

views:

16

answers:

1

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 after."
+1  A: 

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

titanoboa
The correct order of the texts is beneficial, but not required. This answer is useful, thank you.
Tim McNamara