Improve advanced search performance

Use a union query to avoid using DISTINCT and lots and lots of joins in the
from clause.

Initial tests seem to indicate about a 80% faster (~500ms down from ~800ms)
on querying about 9k tickets).