Here is the code from the provided link after adaptation.
add_filter( 'posts_orderby', 'se344727_custom_search_order', 10, 2 );
function se344727_custom_search_order( $orderby, $query )
{
global $wpdb;
if (!is_admin() && $query->is_main_query())
{
if ($query->is_search)
{
// -- sort by: type, title, date --
// " ELSE 2 END ASC, " . $orderby;
// -- sort by: type, date --
// " ELSE 2 END ASC, {$wpdb->prefix}posts.post_date DESC;
$orderby =
" CASE WHEN {$wpdb->prefix}posts.post_type="page" THEN 1 " .
" ELSE 2 END ASC, " .
$orderby;
}
}
return $orderby;
}