def compose_base_find_query(user_id: str, administrator: bool, groups: list):
    """
    Compose a query for filtering reference search results based on user read rights.

    :param user_id: the id of the user requesting the search
    :param administrator: the administrator flag of the user requesting the search
    :param groups: the id group membership of the user requesting the search
    :return: a valid MongoDB query

    """
    if administrator:
        return dict()

    is_user_member = {
        "users.id": user_id
    }

    is_group_member = {
        "groups.id": {
            "$in": groups
        }
    }

    is_owner = {
        "user.id": user_id
    }

    return {
        "$or": [
            is_group_member,
            is_user_member,
            is_owner
        ]
    }