Index a string of comma-separated values

<?php

add_filter( 'facetwp_index_row', function( $params, $class ) {
    if ( 'categories' == $params['facet_name'] ) {
        $values = explode( ', ', $params['facet_value'] );
        foreach ( $values as $val ) {
            $params['facet_value'] = $val;
            $params['facet_display_value'] = $val;
            $class->insert( $params );
        }
        $params['facet_value'] = ''; // skip default indexing
    }
    return $params;
}, 10, 2 );