def get_capture_groups(hit, pos_tags=False):
    """Get CQL labeled groups from a search result

    Parameters
    ----------
    hit : dict
        The returned data of the BlackLab api, see search().
    pos_tags : bool, optional
        Whether to include PoS tags in the returned data, by default False,
        which only includes word forms.

    Returns
    -------
    dict
        A dictionary with keys matching the CQL labeled group name and 
        values the corresponding captured keywords captured in a CQL named group.
    """
    s_idx = hit['start']
    
    fullcntx_words = hit['left']['word'] + hit['match']['word'] + hit['right']['word']
    fullcntx_tags = hit['left']['pos'] + hit['match']['pos'] + hit['right']['pos']
    
    groups = {}
    for g in hit['captureGroups']:
        start, end = g['start'] - s_idx, g['end'] - s_idx
        
        tokens = fullcntx_words[start:end]
        if pos_tags:
            tags = fullcntx_tags[start:end]
            tokens = [(tokens[i], tags[i]) for i in range(len(tokens))]
        
        groups[g['name']] = tokens
    
    return groups