Thanks for your response Tom!
Actually I had tried that article before asking here but it gave me a functions.php error, so I thought maybe a different code is necessary for Generatepress. If that code works for you maybe it was about a plugin I use (Page Tags).
There are specific pages I wanted to exclude from the search.
As a workaround I created a new author, made it the author for these specific pages and excluded this author from the results (with the code from the same article). It worked well both for the widget and the nav search.
function wpb_search_filter( $query ) {
if ( $query->is_search && !is_admin() )
$query->set( 'author','-24' );
return $query;
}
add_filter( 'pre_get_posts', 'wpb_search_filter' );