示例#1
0
    def valueindexes(self):
        indexes = self.catalog.indexes

        # This function determines all indexes whose values should be respected
        # in the report key. The number of unique values for the index needs to
        # be lower than the MAX_DISTINCT_VALUES watermark.

        # TODO: Ideally who would only consider those indexes with a small
        # number of unique values, where the number of items for each value
        # differs a lot. If the number of items per value is similar, the
        # duration of a query is likely similar as well.
        value_indexes = PriorityMap.get_entry(self.cid, VALUE_INDEX_KEY)
        if isinstance(value_indexes, (frozenset, set)):
            # Calculating all the value indexes is quite slow, so we do this
            # once for the first query. Since this is an optimization only,
            # slightly outdated results based on index changes in the running
            # process can be ignored.
            return value_indexes

        value_indexes = set()
        for name, index in indexes.items():
            if IUniqueValueIndex.providedBy(index):
                values = index.uniqueValues()
                if values and len(list(values)) < MAX_DISTINCT_VALUES:
                    # Only consider indexes which actually return a number
                    # greater than zero
                    value_indexes.add(name)

        value_indexes = frozenset(value_indexes)
        PriorityMap.set_entry(self.cid, VALUE_INDEX_KEY, value_indexes)
        return value_indexes
示例#2
0
    def valueindexes(self):
        indexes = self.catalog.indexes

        # This function determines all indexes whose values should be respected
        # in the report key. The number of unique values for the index needs to
        # be lower than the MAX_DISTINCT_VALUES watermark.

        # TODO: Ideally who would only consider those indexes with a small
        # number of unique values, where the number of items for each value
        # differs a lot. If the number of items per value is similar, the
        # duration of a query is likely similar as well.
        value_indexes = PriorityMap.get_entry(self.cid, VALUE_INDEX_KEY)
        if isinstance(value_indexes, (frozenset, set)):
            # Calculating all the value indexes is quite slow, so we do this
            # once for the first query. Since this is an optimization only,
            # slightly outdated results based on index changes in the running
            # process can be ignored.
            return value_indexes

        value_indexes = set()
        for name, index in indexes.items():
            if IUniqueValueIndex.providedBy(index):
                values = index.uniqueValues()
                if values and len(list(values)) < MAX_DISTINCT_VALUES:
                    # Only consider indexes which actually return a number
                    # greater than zero
                    value_indexes.add(name)

        value_indexes = frozenset(value_indexes)
        PriorityMap.set_entry(self.cid, VALUE_INDEX_KEY, value_indexes)
        return value_indexes
示例#3
0
    def getAllowedCriterias(self, instance):
        """return a tuple of allowed search criterias ids"""
        ct = getToolByName(instance, 'portal_catalog')
        criterias = self.allowed_criterias
        if criterias is None:
            criterias = ct.indexes()

        indexes = ct.getIndexObjects()
        criterias = [
            i.getId() for i in indexes if i.getId() in criterias and (i.getId(
            ) == 'SearchableText' or (IUniqueValueIndex.providedBy(i) and not (
                IDateIndex.providedBy(i) or IDateRangeIndex.providedBy(i))))
        ]

        def lowcase_cmp(s1, s2):
            return cmp(s1.lower(), s2.lower())

        criterias.sort(lowcase_cmp)
        return tuple(criterias)
示例#4
0
    def valueindexes(self):
        indexes = self.catalog.indexes

        # This function determines all indexes whose values should be respected
        # in the report key. The number of unique values for the index needs to
        # be lower than the MAX_DISTINCT_VALUES watermark.

        # Ideally who would only consider those indexes with a small
        # number of unique values, where the number of items for each value
        # differs a lot. If the number of items per value is similar, the
        # duration of a query is likely similar as well. However, calculating
        # all the value indexes with the number of items per value is
        # quite slow. Therefore, we do not make this distinction.
        value_indexes = PriorityMap.get_entry(self.cid, VALUE_INDEX_KEY)
        if isinstance(value_indexes, (frozenset, set)):
            # Since this is an optimization only, slightly outdated results
            # based on index changes in the running process can be ignored.
            return value_indexes

        value_indexes = set()
        for name, index in indexes.items():
            if IUniqueValueIndex.providedBy(index):

                # DateRangeIndex is unsuitable for this purpose
                if IDateRangeIndex.providedBy(index):
                    continue

                # the size of an UniqueValueIndex is typically equal to the
                # number of unique values
                isize = index.indexSize()
                if isize >= MAX_DISTINCT_VALUES:
                    continue

                value_indexes.add(name)

        value_indexes = frozenset(value_indexes)
        PriorityMap.set_entry(self.cid, VALUE_INDEX_KEY, value_indexes)
        return value_indexes
    def getAllowedCriterias(self, instance):
        """return a tuple of allowed search criterias ids"""
        ct = getToolByName(instance, 'portal_catalog')
        criterias = self.allowed_criterias
        if criterias is None:
            criterias = ct.indexes()

        indexes = ct.getIndexObjects()
        criterias = [i.getId() for i in indexes
                     if i.getId() in criterias
                     and (i.getId() == 'SearchableText'
                          or (IUniqueValueIndex.providedBy(i)
                              and not (IDateIndex.providedBy(i) or
                                       IDateRangeIndex.providedBy(i))
                              )
                          )
                     ]
                     
        def lowcase_cmp(s1, s2):
            return cmp(s1.lower(), s2.lower())
        
        criterias.sort(lowcase_cmp)
        return tuple(criterias)