Database search fixes:

- Move filter() function and make it protected, nothing uses it
  outside database-backed searching
- Use per-backend legal search characters rather than assuming the
  static implementation is right

Change-Id: Ic2b830b56137b2dfe68b9b9c3de012151e716952
Merge "Database search fixes:"