Search fixes

- Fixed #2928
- Misc fixes

review: @devoncarew

A named constant would be nice here.