Improved logic to collapse search terms that match when ignoring case