def reduce_subjects(doc):
    """Iterates and sort all topic and subject related fields and
    returns a set of unique subjects.

    :param doc: Dictionary of subject values from the Solr document
                query
    :rtype: Set of subject terms
    """
    subjects = []
    if doc.has_key('subject'):
        for subject in doc['subject']:
            subjects.append(subject)
    if doc.has_key('topic'):
        for topic in doc.get('topic'):
            subjects.append(topic)
    subjects.sort()
    return set(subjects)