Copying search refinement

Making the same search refinement here. Probably this should be two separate patches. If you want I can split them.