Share shards computation logic between searchShards and searchShardsCoun...

This PR refactors a bit and add a shared method for searchShards and searchShardsCount to avoid divergent behavior in the future (like #2682 and #3268).

It seems like searchShardsCount is mainly implemented to test if we are hitting 1 shard or more than 1 shards so maybe it could be renamed and optimized for that specific use case.