Append the post type to autocomplete facet results

<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    $name = $params['facet_name'];

    // Force-index data from one facet into another
    if ( 'search_by_name' == $name ) {
        $params['facet_name'] = 'category';
    }

    // Append the post type to the facet choice label
    if ( in_array( $name, [ 'search_by_name', 'category' ] ) ) {
        $post_id = (int) $params['post_id'];
        $post_type = get_post_type( $post_id );
        $params['facet_display_value'] .= ' (' . $post_type . ')';
    }

    return $params;
}, 10, 2 );