Name your keyword input just s
<input name="s" type="text" placeholder="Filter by keyword" value=""/>
This is enough for WP to recognize the request as search plus you won’t have to do the $query->set( 's', ... )
later
In pre_get_posts
action use the conditional is_post_type_archive( 'document' )
so your if statement look something like this:
if ( is_post_type_archive('document') && is_search() ) {
...
}
Hope that helps
Update
Since you’re searching, search template (search.php, index.php) will take precedence over the archive. You will need to filter the template which WP assigns for those requests as well.
add_filter( 'search_template', function ( $template ) {
if ( is_post_type_archive('document') && is_search() ) {
$find_template = locate_template( ['archive-document.php'] );
if ( '' !== $find_template ) {
$template = $find_template;
}
}
return $template;
});