CouchDB multiple tags

前端 未结 6 1534
梦如初夏
梦如初夏 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:07

    I think the following should give you a slightly complicated but solid algorithm -- i.e. it does finds the first results fast, even if you have very many documents. It will probably not perform well in practice :(

    Index the documents by each single tag and there document id:

    [, ]
    

    E.g. for the documents document

    • docid1 with the tags [blue, green, red]
    • docid2 with the tags [blue, yellow]

    you get

    ['blue', 'docid1']
    ['blue', 'docid2']
    ['green', 'docid1']
    ['red', 'docid1']
    ['yellow', 'docid2']
    

    Now for each tag you want to search for you open a parallel search starting at [tag, ...].

    For each tag you maintain a current search position. If the docids at all your searches match, you found a match. If they do not match, try to skip to at least the highest document id via a range search. Repeat.

    [It's basically a join.]

    The skipping is theoretically fast: We have an index to find these documents. Practically, it's probably slow because of all the round trips to the server. It would be nice to be able to offload that algorithm to a function executed on the server. Is that possible?

提交回复
热议问题