CouchDB multiple tags

前端 未结 6 1538
梦如初夏
梦如初夏 2021-02-13 16:25

Is there any way to have multiple tag search implemented in CouchDB? I have documents (posts) each with multiple tags. I need to find posts that have been tagged with an arbitra

6条回答
  •  生来不讨喜
    2021-02-13 17:13

    So, as far as I understood the answer is NO. CouchDB can't query for documents having presence of multiple tags (workaround with lucene or mysql doesn't count, this way we lost some features of CouchDB). Sad news :(.

    (having presence of multiple tags - having both A and B, not A or B)

    UPD! It's possible but with limitations to only 2-3 tags.

    http://wiki.apache.org/couchdb/EntityRelationship

    Querying by multiple keys

    Some applications need to view the intersection of entities that have multiple keys. In the example above, this would be a query for the contacts who are in both the "Friends" and the "Colleagues" groups. The most straight-forward way to handle this situation is to query for one of the keys, and then to filter by the rest of the keys on the client-side. If the key frequencies vary greatly, it may also be worthwhile to make an initial call to determine the key with the lowest frequency, and to use that to fetch the initial document list from the database.

    If this is not a good option, it is possible to index the combinations of the keys, though the growth of the index for a given document will be exponential with the number of its keys. Still, for small-ish key sets, this is an option, since the keys can be ordered, and keys which are prefixes of a larger key can be omitted. For instance, for the key set [1 2 3] the possible key combinations are [1] [2] [3] [1 2] [1 3] [2 3] [1 2 3] However, the index need only contain the keys [3] [1 3] [2 3] [1 2 3] since (for example) the documents matching the keys [1 2] could be obtained with a query for startkey=[1,2,null] and endkey=[1,2,{}] The number of index entries will be 2^(n-1) number of keys.

    A final option is to use a separate index, such as couchdb-lucene to help with such queries.

提交回复
热议问题