Improve search matching algorithm.
Wrap shared search code in an anaonymous block.