Refactor search controller

This removes some duplication, and should make it easier to implement experimental tabs with merged indices.

Based on work by and with @fatbusinessman