I'm using CouchDB to store and process emails.
Every email has a "message-id" header field containing a globally unique
identifier and zero or more "references" and "in-reply-to" fields, each
of which contains the message-id of a different message.
To construct a threaded view, a tree structure is built using
"references" and "in-reply-to" as parent links. This implies that a
message can have more than one parent, in which case it would appear
multiple times in the view.
I would like to have a CouchDB view that allows me to easily construct
threads in this way. Specifically, given a particular message, I want to
get all of its directly or indirectly connected messages. Messages don't
need to be in any particular order within a thread. It can be assumed
that a thread contains a small number of messages, say <100
The view might have one or more other key fields (e.g. date) which will
be used to sort the threads or restrict the range. When a range is
given, the view returns all messages from each thread that contains at
least one message in the range.
I want to be able to handle each of these cases with one request,
without storing intermediate data in documents.