Inverted index possible from couchdb view?

Suppose I have couchdb docs that look like this:

{
    "_id": "id",
    "_rev": "rev",
    "title": "foobar",
    "URI": "http://www.foobar.com",
    "notes": "",
    "date": 1334177254774,
    "tags": [
        "tag1",
        "tag2",
        "tag3"
    ],
    "date_modified": 1334177278457,
    "deleted": false
}

I want to create an inverted index from tags, so I get something like:

{
    "tag1": [
        _id,
        _id,
        _id
    ],
    "tag2": [
        _id,
        _id,
        ...
    ]
}

From what I read and tried, couchdb may not have allowed me to do this. I cannot do this in the card phase, and it seems I cannot do this in the couch cut phase. Is this something I need to execute in another application layer?

+3
source share
1 answer

You can achieve this with the CouchDB card feature.

CouchDB , . , " " , , , .

// View rows (conceptual diagram)
// Key  , Value
[ "tag1", "_id1"
, "tag1", "_id2"
, "tag1", "_id3"

, "tag2", "_id2"
, "tag2", "_id4"
, "tag3", "_id6"
]

, GET /db/_design/ddoc/_view/tags?key="tag1".

. lagniappe "reduce" "_count", ( ). &reduce=false, .

+3

All Articles