'Find the course_index matching particular conditions.
Arguments:
branch: If specified, this branch must exist in the returned courses
search_targets: If specified, this must be a dictionary specifying field values
that must exist in the search_targets of the returned courses
org_target: If specified, this is an ORG filter so that only course_indexs are
returned for the specified ORG'

def find_matching_course_indexes(self, branch=None, search_targets=None, org_target=None, course_context=None):

    with TIMER.timer('find_matching_course_indexes', course_context):
        query = {}
        if (branch is not None):
            query['versions.{}'.format(branch)] = {'$exists': True}
        if search_targets:
            for (key, value) in search_targets.iteritems():
                query['search_targets.{}'.format(key)] = value
        if org_target:
            query['org'] = org_target
        return self.course_index.find(query)
