def index_documents(self, mapping, temp_index_base): model = mapping.get_model() self.stdout.write('Indexing %s' % self.full_name(model)) if mapping.has_deleted(): model_objs = model.objects.filter(is_deleted=False) else: model_objs = model.objects.all() index_objects(mapping, model_objs, temp_index_base, print_progress=True)
def index_documents(self, mapping, temp_index_base): """ Index all non deleted objects. """ model = mapping.get_model() self.stdout.write('Indexing {0}.{1}'.format(model.__module__, model.__name__).lower()) if mapping.has_deleted(): model_objs = model.objects.filter(is_deleted=False) else: model_objs = model.objects.all() index_objects(mapping, model_objs, temp_index_base, print_progress=True)
def index(self, index_name, specific_targets=None, ids=None): """ Index objects from our index-enabled models. """ for mapping_class in ModelMappings.get_model_mappings().values(): model = mapping_class.get_model() # Skip this model if there are specific targets and not specified. if not self.model_targetted(model, specific_targets): continue model = mapping_class.get_model() if ids: for arg_id in ids: try: obj = model.objects.get(id=arg_id) except model.DoesNotExist: self.stdout.write( 'ID does not exist, deleting %s for %s' % (arg_id, self.full_name(model))) mapping_class.unindex(arg_id, index=index_name) else: if mapping_class.has_deleted() and obj.is_deleted: self.stdout.write( 'ID is_deleted, deleting %s for %s' % (arg_id, self.full_name(model))) mapping_class.unindex(arg_id, index=index_name) else: self.stdout.write('ID updating %s for %s' % (arg_id, self.full_name(model))) document = mapping_class.extract_document( arg_id, obj) mapping_class.bulk_index([document], id_field='id', index=index_name) return self.stdout.write('Indexing %s' % self.full_name(model)) if mapping_class.has_deleted(): model_objs = model.objects.filter(is_deleted=False) else: model_objs = model.objects.all() index_objects(mapping_class, model_objs, index_name, print_progress=True)
def index(self, index_name, specific_targets=None, ids=None): """ Index objects from our index-enabled models. """ for mapping_class in ModelMappings.get_model_mappings().values(): model = mapping_class.get_model() # Skip this model if there are specific targets and not specified. if not self.model_targetted(model, specific_targets): continue model = mapping_class.get_model() if ids: for arg_id in ids: try: obj = model.objects.get(id=arg_id) except model.DoesNotExist: self.stdout.write('ID does not exist, deleting %s for %s' % (arg_id, self.full_name(model))) mapping_class.unindex(arg_id, index=index_name) else: if mapping_class.has_deleted() and obj.is_deleted: self.stdout.write('ID is_deleted, deleting %s for %s' % (arg_id, self.full_name(model))) mapping_class.unindex(arg_id, index=index_name) else: self.stdout.write('ID updating %s for %s' % (arg_id, self.full_name(model))) document = mapping_class.extract_document(arg_id, obj) mapping_class.bulk_index([document], id_field='id', index=index_name) return self.stdout.write('Indexing %s' % self.full_name(model)) if mapping_class.has_deleted(): model_objs = model.objects.filter(is_deleted=False) else: model_objs = model.objects.all() index_objects(mapping_class, model_objs, index_name, print_progress=True)