Refactor out part of _do_search; some efficiency.