def filter_queryset_metadata_category(queryset, category, category_strict):
    """ Filters a given REST framework queryset by a given query.

    Only keeps elements which title, abstract or keyword can be matched to the given query.

    Args:
        queryset: A queryset containing elements
        category: A list of ids
        category_strict: Whether to evaluate multiple ids using AND or OR
    Returns:
        queryset: The given queryset which only contains matching elements
    """
    if category is not None and len(category) > 0:
        # DRF automatically replaces '+' to ' ' whitespaces, so we work with this
        category_list = category.split(" ")

        queryset = queryset.filter(
            categories__id__in=category_list
        ).distinct()
        if category_strict:
            for category in category_list:
                queryset = queryset.filter(categories__id=category)

    return queryset