HSEARCH-1583

Note: it would be nice to backport this to 4.4 and 4.5.