Provide fast suggestions for tag components.

    This yields suggestions for *components* of a tag and a given
    prefix. For example, given the tags ``foo/bar/baz`` and
    ``fob/bob``, here are some example completions (ordering may be
    different):

    .. code-block:: text

        /dossier/v1/tags/suggest/prefix/f => ['foo', 'fob']
        /dossier/v1/tags/suggest/prefix/foo => ['foo']
        /dossier/v1/tags/suggest/prefix/b/parent/foo => ['bar']
        /dossier/v1/tags/suggest/prefix/b/parent/fob => ['bob']
        /dossier/v1/tags/suggest/prefix/b/parent/foo/bar => ['baz']

    N.B. Each of the lists above are wrapped in the following
    JSON envelope for the response:

    .. code-block:: text

        {'suggestions': ['foo', 'fob']}

    An optional query parameter, ``limit``, may be passed to control
    the number of suggestions returned.

def v1_tag_suggest(request, tags, prefix, parent=''):
    '''Provide fast suggestions for tag components.

    This yields suggestions for *components* of a tag and a given
    prefix. For example, given the tags ``foo/bar/baz`` and
    ``fob/bob``, here are some example completions (ordering may be
    different):

    .. code-block:: text

        /dossier/v1/tags/suggest/prefix/f => ['foo', 'fob']
        /dossier/v1/tags/suggest/prefix/foo => ['foo']
        /dossier/v1/tags/suggest/prefix/b/parent/foo => ['bar']
        /dossier/v1/tags/suggest/prefix/b/parent/fob => ['bob']
        /dossier/v1/tags/suggest/prefix/b/parent/foo/bar => ['baz']

    N.B. Each of the lists above are wrapped in the following
    JSON envelope for the response:

    .. code-block:: text

        {'suggestions': ['foo', 'fob']}

    An optional query parameter, ``limit``, may be passed to control
    the number of suggestions returned.
    '''
    prefix = prefix.decode('utf-8').strip()
    parent = parent.decode('utf-8').strip()
    limit = min(10000, int(request.params.get('limit', 100)))
    return {'suggestions': tags.suggest(parent, prefix, limit=limit)}