Example #1
0
    def update_backend(self, backend_name, schema_only=False):
        self.stdout.write("Updating backend: " + backend_name)

        backend = get_search_backend(backend_name)

        if not backend.rebuilder_class:
            self.stdout.write("Backend '%s' doesn't require rebuilding" %
                              backend_name)
            return

        models_grouped_by_index = group_models_by_index(
            backend, get_indexed_models()).items()
        if not models_grouped_by_index:
            self.stdout.write(backend_name + ": No indices to rebuild")

        for index, models in models_grouped_by_index:
            self.stdout.write(backend_name +
                              ": Rebuilding index %s" % index.name)

            # Start rebuild
            rebuilder = backend.rebuilder_class(index)
            index = rebuilder.start()

            # Add models
            for model in models:
                index.add_model(model)

            # Add objects
            object_count = 0
            if not schema_only:
                for model in models:
                    self.stdout.write('{}: {}.{} '.format(
                        backend_name, model._meta.app_label,
                        model.__name__).ljust(35),
                                      ending='')

                    # Add items (1000 at a time)
                    for chunk in self.print_iter_progress(
                            self.queryset_chunks(
                                model.get_indexed_objects().order_by('pk'))):
                        index.add_items(model, chunk)
                        object_count += len(chunk)

                    self.print_newline()

            # Finish rebuild
            rebuilder.finish()

            self.stdout.write(backend_name +
                              ": indexed %d objects" % object_count)
            self.print_newline()
Example #2
0
    def update_backend(self, backend_name, schema_only=False):
        self.stdout.write("Updating backend: " + backend_name)

        backend = get_search_backend(backend_name)

        if not backend.rebuilder_class:
            self.stdout.write("Backend '%s' doesn't require rebuilding" % backend_name)
            return

        models_grouped_by_index = group_models_by_index(backend, get_indexed_models()).items()
        if not models_grouped_by_index:
            self.stdout.write(backend_name + ": No indices to rebuild")

        for index, models in models_grouped_by_index:
            self.stdout.write(backend_name + ": Rebuilding index %s" % index.name)

            # Start rebuild
            rebuilder = backend.rebuilder_class(index)
            index = rebuilder.start()

            # Add models
            for model in models:
                index.add_model(model)

            # Add objects
            object_count = 0
            if not schema_only:
                for model in models:
                    self.stdout.write('{}: {}.{} '.format(backend_name, model._meta.app_label, model.__name__).ljust(35), ending='')

                    # Add items (1000 at a time)
                    for chunk in self.print_iter_progress(self.queryset_chunks(model.get_indexed_objects())):
                        index.add_items(model, chunk)
                        object_count += len(chunk)

                    self.print_newline()

            # Finish rebuild
            rebuilder.finish()

            self.stdout.write(backend_name + ": indexed %d objects" % object_count)
            self.print_newline()
Example #3
0
    def update_backend(self, backend_name, schema_only=False):
        # Print info
        self.stdout.write("Updating backend: " + backend_name)

        # Get backend
        backend = get_search_backend(backend_name)

        # Get rebuilder
        rebuilder = backend.get_rebuilder()

        if not rebuilder:
            self.stdout.write(backend_name + ": Backend doesn't require rebuild. Skipping")
            return

        # Start rebuild
        self.stdout.write(backend_name + ": Starting rebuild")
        index = rebuilder.start()

        for model in get_indexed_models():
            self.stdout.write(backend_name + ": Indexing model '%s.%s'" % (
                model._meta.app_label,
                model.__name__,
            ))

            # Add model
            index.add_model(model)

            # Index objects
            object_count = 0
            if not schema_only:
                # Add items (1000 at a time)
                for chunk in self.print_iter_progress(self.queryset_chunks(model.get_indexed_objects())):
                    index.add_items(model, chunk)
                    object_count += len(chunk)

            self.stdout.write("(indexed %d objects)" % object_count)
            self.print_newline()

        # Finish rebuild
        self.stdout.write(backend_name + ": Finishing rebuild")
        rebuilder.finish()
Example #4
0
def register_signal_handlers():
    # Loop through list and register signal handlers for each one
    for model in get_indexed_models():
        post_save.connect(post_save_signal_handler, sender=model)
        post_delete.connect(post_delete_signal_handler, sender=model)
Example #5
0
def register_signal_handlers():
    # Loop through list and register signal handlers for each one
    for model in get_indexed_models():
        post_save.connect(post_save_signal_handler, sender=model)
        post_delete.connect(post_delete_signal_handler, sender=model)
Example #6
0
 def get_object_list(self):
     # Return list of (model_name, queryset) tuples
     return [
         (model, model.get_indexed_objects())
         for model in get_indexed_models()
     ]
Example #7
0
 def get_object_list(self):
     # Return list of (model_name, queryset) tuples
     return [
         (model, model.get_indexed_objects())
         for model in get_indexed_models()
     ]