On Thu, Nov 18, 2010 at 5:00 AM, Nicolas Jessus <nicolas.jes...@lores.org>wrote:

>
> Naively, the key should be something like [clientName, dateMP1, dateM1], or
> maybe [clientName] and a value of [dateMP1, dateM1]. There can be hundreds
> of
> thousands of meetings. The problem is to generate the key triplet when
> there's
> no common ID between the documents.


you can only emit a result from the map function if key elements to be used
are in the document currently being indexed.
if you want [clientName] then the field clientName has to exist in the
document.
if you want [dateMP1, dateM1] then those fields have to exist in the
document.

example, car data - this is what i currently deal with :)

document{
make: honda
family: accord
variant: euro
}

document{
make: honda
family: accord
variant: v6
}
document{
make: toyota
family: camry
variant: something
}
then i can create a view to emit all makes
function(doc) {
  if(doc.make) {
    emit(doc.make,1)
  }
}

then I'll get a view with results like
{rows: [
  {key:honda, value:1},
  {key:honda, value:1},
  {key:toyota, value:1}
]}

put in a reduce function and i get totals (using group=true)
function(keys, values) {
  return sum(values);
}
result
{rows: [
  {key:honda, value:2},
  {key:toyota, value:1}
]}

now i want to know how many of each make & family i update the view map
function
function(doc) {
  if(doc.make && doc.family) {
    emit([doc.make, doc.family),1)
  }
}

result (using group=true)
{rows: [
  {key:[honda,accord], value:2},
  {key:[toyota,camry], value:1}
]}

result (using group=true&group_level=1)
{rows: [
  {key:[honda], value:2},
  {key:[toyota], value:1}
]}

so looking at what you are trying to do I don't see how it is possible to
have separate documents emiting keys from other documents (a single document
goes into the map function) using map/reduce - you are probably going to
have to use a list or one of the lucene projects to combine views together.
or figure out a way to put all the data into denormalised document, which
you have said isn't going to work.

regarding the re-index concern of yours, if the data changes couchdb takes
care of the views/lists, you don't have to force it to do anything - what am
I missing?

Nicholas :)

(hopefully i got all that right....)

Reply via email to