-- Support cast-to-text search filters on installations where DOC type columns are varchar.
-- These indexes align with the query shape used by generic search filters.

CREATE INDEX IF NOT EXISTS idx_doc_document_type_family_text_updated
    ON DOC.doc_document ((CAST(document_type AS text)), (CAST(document_family AS text)), updated_at DESC, id);

CREATE INDEX IF NOT EXISTS idx_doc_document_type_family_visibility_text_updated
    ON DOC.doc_document (
        (CAST(document_type AS text)),
        (CAST(document_family AS text)),
        (CAST(visibility AS text)),
        updated_at DESC,
        id
    );

CREATE INDEX IF NOT EXISTS idx_doc_text_repr_primary_type_text_document
    ON DOC.doc_text_representation (is_primary, (CAST(representation_type AS text)), document_id);
