def _get_offset_ann_map(ann_objs, restrict_types=None, ignore_types=None):
    """
    Helper function for search. Given annotations, returns a dict
    mapping offsets in text into the set of annotations spanning each
    offset.
    """
    restrict_types = [] if restrict_types is None else restrict_types
    ignore_types = [] if ignore_types is None else ignore_types
    offset_ann_map = {}
    for ann_obj in ann_objs:
        for text in ann_obj.get_textbounds():
            if text.type in ignore_types:
                continue
            if restrict_types != [] and text.type not in restrict_types:
                continue
            for t_start, t_end in text.spans:
                for i in range(t_start, t_end):
                    if i not in offset_ann_map:
                        offset_ann_map[i] = set()
                    offset_ann_map[i].add(text)
    return offset_ann_map
