FacetWP – when sorting by rating, prevent results with no ratings from disappearing

<?php

function fwp_preserve_unrated_posts( $query ) {
    if ( 'rating' == $query->get( 'meta_key' ) ) {
        $query->set( 'meta_query', array(
            'relation' => 'OR',
             array(
                'key' => 'rating',
                'compare' => 'NOT EXISTS'
            ),
            array(
                'key' => 'rating',
                'compare' => 'EXISTS',
            )
        ) );
    }
}
add_filter( 'pre_get_posts', 'fwp_preserve_unrated_posts' );