def METHOD_NAME(q, target_type, window_size=2000):
    query, kwargs = Target.objects.search_query(q, target_type)
    with transaction.atomic(), connection.cursor() as cursor:
        cursor.execute(f"DECLARE santa_targets_export_cursor CURSOR FOR {query}", kwargs)
        while True:
            cursor.execute("FETCH %s FROM santa_targets_export_cursor", [window_size])
            results = cursor.fetchall()
            if not results:
                break
            for target_type, identifier, obj, _, rule_count in results:
                obj = json.loads(obj)
                row = [("identifier", identifier),
                       ("rule count", rule_count)]
                for k, v in sorted(obj.items()):
                    row.append((k.replace("_", " "), v if v is not None else ""))
                yield target_type, row