import re


def _sanitize_search_results(match):
    """Cleans up search results.

    - Removes the pretext "New testimonial..."
    - Removes the fields at the bottom for voting/publishing
    - Fixes up the learner's name
    """
    if not 'attachments' in match or len(match['attachments']) == 0:
        return None

    testimonial = match['attachments'][0]
    testimonial['pretext'] = None
    testimonial['fields'] = []

    name = None
    name_match = re.match("\.\.\.from '(\\w*)'", testimonial.get('title', ''))
    if name_match:
        name = name_match.group(1)

    testimonial['title'] = name or "Anonymous"

    return testimonial