Refactor search controller

This removes some duplication, and should make it easier to implement
experimental tabs with merged indices.