Scribd's discovery systems receive an unsorted array of document metadata. Implement a function that searches documents by text, applies dynamic filters, and groups the matching document IDs by a requested metadata field.
The search is case-insensitive and matches the document's title, author, or any value in tags. A blank or None query matches every document. Filters are supplied as a dictionary:
tags.{"min": 2015, "max": 2024} applies inclusive bounds. Either bound may be omitted.Return a dictionary mapping each group value to a list of matching document IDs. Preserve the input order within each group and omit groups with no matches.
Implement search_filter_group(documents, query, filters, group_by), where documents is a list of dictionaries, query is a string or None, filters is a dictionary, and group_by is a metadata field name. Return a dictionary whose keys are string representations of group values and whose values are lists of IDs.
def search_filter_group(documents, query, filters, group_by):