Improve search.py performance in --keys-only mode