def format_query_results(md_update, query_obj):
    """Format the query results and return some data structures."""
    valid_ids = []
    display_data = {}
    for obj in md_update[query_obj.metaID].query_results:
        valid_ids.append(str(obj[query_obj.valueField]))
        display_data[str(obj[query_obj.valueField])] = md_update[query_obj.
            metaID].displayFormat.format(**obj)
    return valid_ids, display_data
