Frage

I need to make a view that emits a value for each pair of documents (A cartesian product of _all_docs with itself)

For example, assume DB has documents with IDs a, b, c -> then the view should emit 9 keys aa, ab, ac, ba, ... , cc (assuming no grouping)

E.g. if the documents are "cities" with coordinates, the view returns pairs of cities and distance between them (real example is more complicated), so I could then use _list function to compute "top10 closest cities" and so on.

This looks like a very simple task, however Google and SO search gives no results. Am I missing some magic keyword here?

War es hilfreich?

Lösung

I can't think of a way to do this in CouchDB - fundamentally, this doesn't lend itself to map/reduce indexes - in the map function you only have access to one document at a time and in the reduce stage you need to reduce the result (computing the cartesian product would expand it).

If you use another system to precompute the distances between the cities then CouchDB is likely a good fit for storing and querying the result of that cartesian product (to e.g. find the top 10 closest cities). However, you might also want to look at a graph database (Neo4j or Giraph) as well.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top