def METHOD_NAME(
    cls,
    collection,
    parent=None,
    foreign_id=None,
    content_hash=None,
    meta=None,
    role_id=None,
):
    """Try and find a document by various criteria."""
    foreign_id = sanitize_text(foreign_id)
    q = cls.all()
    q = q.filter(Document.collection_id == collection.id)
    if parent is not None:
        q = q.filter(Document.parent_id == parent.id)
    if foreign_id is not None:
        q = q.filter(Document.foreign_id == foreign_id)
    elif content_hash is not None:
        q = q.filter(Document.content_hash == content_hash)
    else:
        raise ValueError("No unique criterion for document.")
    document = q.first()
    if document is None:
        document = cls()
        document.schema = cls.SCHEMA
        document.collection_id = collection.id
        document.role_id = role_id
    if parent is not None:
        document.parent_id = parent.id
    if foreign_id is not None:
        document.foreign_id = foreign_id
    document.content_hash = content_hash
    if content_hash is None:
        document.schema = cls.SCHEMA_FOLDER
    if meta is not None:
        document.update(meta)
    db.session.add(document)
    return document