the_posts hook, which set of posts?

I’d say it’s perfectly fine to do it the way you’re doing it now, that is

function my_the_posts($posts, $query = false) {
    if( is_search() ){
        // do your thing here
    }
    return $posts;
}
add_filter( 'the_posts', 'my_the_posts' );

Don’t worry about those excerpts in the footer, even though they may be part of the search page (which the footer will be, obviously), they’re part of a different query and so will not pass the is_search() test.

tech