(self, index, query_analysis)
return OrderedDict({
            'coverage': coverage,
            'idealOrder': ideal_order,
            'queryFieldsCovered': query_fields_covered,
            'index': index,
            'supported': supported
        })
Analyzes an existing index against the results of query analysis
Analyzes an existing index against the results of query analysis
Analyzes an existing index against the results of query analysis
def _generate_index_report(self, index, query_analysis):
        """Analyzes an existing index against the results of query analysis"""

        all_fields = []
        equiv_fields = []
        sort_fields = []
        range_fields = []

        for query_field in query_analysis['analyzedFields']:
            all_fields.append(query_field['fieldName'])
            if query_field['fieldType'] is EQUIV_TYPE:
                equiv_fields.append(query_field['fieldName'])
            elif query_field['fieldType'] is SORT_TYPE:
                sort_fields.append(query_field['fieldName'])
            elif query_field['fieldType'] is RANGE_TYPE:
                range_fields.append(query_field['fieldName'])

        max_equiv_seq = len(equiv_fields)
        max_sort_seq = max_equiv_seq + len(sort_fields)
        max_range_seq = max_sort_seq + len(range_fields)

        coverage = 'none'
        query_fields_covered = 0
        query_field_count = query_analysis['fieldCount']
        supported = True
        ideal_order = True
        for index_field in index['key']:
            field_name = index_field[0]

            if index_field[1] == '2d':
                supported = False
                break

            if field_name not in all_fields:
                break

            if query_fields_covered == 0:
                coverage = 'partial'

            if query_fields_covered < max_equiv_seq:
                if field_name not in equiv_fields:
                    ideal_order = False
            elif query_fields_covered < max_sort_seq:
                if field_name not in sort_fields:
                    ideal_order = False
            elif query_fields_covered < max_range_seq:
                if field_name not in range_fields:
                    ideal_order = False
            query_fields_covered += 1
        if query_fields_covered == query_field_count:
            coverage = 'full'

        # INDEX REPORT
        return OrderedDict({
            'coverage': coverage,
            'idealOrder': ideal_order,
            'queryFieldsCovered': query_fields_covered,
            'index': index,
            'supported': supported
        })
def _generate_index_report ( self , index , query_analysis ) : all_fields = [ ] equiv_fields = [ ] sort_fields = [ ] range_fields = [ ] for query_field in query_analysis [ 'analyzedFields' ] : all_fields . append ( query_field [ 'fieldName' ] ) if query_field [ 'fieldType' ] is EQUIV_TYPE : equiv_fields . append ( query_field [ 'fieldName' ] ) elif query_field [ 'fieldType' ] is SORT_TYPE : sort_fields . append ( query_field [ 'fieldName' ] ) elif query_field [ 'fieldType' ] is RANGE_TYPE : range_fields . append ( query_field [ 'fieldName' ] ) max_equiv_seq = len ( equiv_fields ) max_sort_seq = max_equiv_seq + len ( sort_fields ) max_range_seq = max_sort_seq + len ( range_fields ) coverage = 'none' query_fields_covered = 0 query_field_count = query_analysis [ 'fieldCount' ] supported = True ideal_order = True for index_field in index [ 'key' ] : field_name = index_field [ 0 ] if index_field [ 1 ] == '2d' : supported = False break if field_name not in all_fields : break if query_fields_covered == 0 : coverage = 'partial' if query_fields_covered < max_equiv_seq : if field_name not in equiv_fields : ideal_order = False elif query_fields_covered < max_sort_seq : if field_name not in sort_fields : ideal_order = False elif query_fields_covered < max_range_seq : if field_name not in range_fields : ideal_order = False query_fields_covered += 1 if query_fields_covered == query_field_count : coverage = 'full' # INDEX REPORT return OrderedDict ( { 'coverage' : coverage , 'idealOrder' : ideal_order , 'queryFieldsCovered' : query_fields_covered , 'index' : index , 'supported' : supported } )