示例#1
0
    def compact_index(self, index):
        """
        Compacts index
        Used for better utilization of index metadata.
        The deleted documents will be not more in structure.

        :param index: the index to destroy
        :type index: :py:class:`CodernityDB.index.Index`` instance, or string
        """
        if isinstance(index, six.string_types):
            if not index in self.indexes_names:
                raise PreconditionsException("No index named %s" % index)
            index = self.indexes_names[index]
        elif not index in self.indexes:
            self.__not_opened()
            raise PreconditionsException("Argument must be Index instance or valid string index format")
        if getattr(index, 'compacting', False):
            raise ReindexException(
                "The index=%s is still compacting" % index.name)
        index.compacting = True
        index.compact()
        del index.compacting
    def reindex_index(self, index):
        """
        Performs reindex on index. Optimizes metadata and storage informations for given index.

        You can't reindex **id** index.

        :param index: the index to reindex
        :type index: :py:class:`CodernityDB.index.Index`` instance, or string
        """
        if isinstance(index, str):
            if not index in self.indexes_names:
                raise PreconditionsException("No index named %s" % index)
            index = self.indexes_names[index]
        elif not index in self.indexes:
            self.__not_opened()
            raise PreconditionsException(
                "Argument must be Index instance or valid string index format")
        if index.name == 'id':
            self.__not_opened()
            raise PreconditionsException("Id index cannot be reindexed")
        if getattr(index, 'reindexing', False):
            raise ReindexException("The index=%s is still reindexing" %
                                   index.name)

        all_iter = self.all('id')
        index.reindexing = True
        index.destroy()
        index.create_index()

        while True:
            try:
                curr = all_iter.next()
            except StopIteration:
                break
            else:
                self._single_reindex_index(index, curr)
        del index.reindexing