def transform(self, model): """ Returns a unique identifier string for the specified object. This avoids duplicate documents """ self.value = self.make_key(get_model_key(model), model.pk) return unicode(self)
def transform(self, model): """ Returns a unique identifier string for the specified object. This avoids duplicate documents """ self.value = "%s%s%s" % (get_model_key(model), settings.SEARCH_SEPARATOR, model.pk) return unicode(self)
def get_document(instance): """ Helper to get document from instance """ key = get_model_key(instance) if key not in registry.keys(): raise NotRegistered('Instance not reqistered with Solango') return registry[key](instance)
def post_delete( sender, instance, *args, **kwargs): """ Apply any necessary post-save moderation steps to new comments. """ key = get_model_key(instance) if key not in registry.keys(): return None document = registry[key](instance) connection.delete([document,])
def post_save(sender, instance, created, *args, **kwargs): """ Apply any necessary pre-save moderation steps to new comments. """ key = get_model_key(instance) if key not in registry.keys(): return None document = registry[key](instance) #Note adding and updating a document in solr uses the same command connection.add([document])
def get_document(instance_or_tuple): """ Helper to get document from either model instance, or tuple in the form (model_key, instance_id) """ if isinstance(instance_or_tuple, tuple): key = instance_or_tuple[0] else: key = get_model_key(instance_or_tuple) if key not in registry.keys(): raise NotRegistered('Instance not reqistered with Solango') return registry[key](instance_or_tuple)
def register(model_or_iterable, search_document=None): if isinstance(model_or_iterable, ModelBase): model_or_iterable = [model_or_iterable] for model in model_or_iterable: #Register the model if model in registry: raise AlreadyRegistered('%s has already been registered by search' % model) if not search_document: #Default Search Document if no document is specified. search_document = SearchDocument key = get_model_key(model) registry[key] = search_document #Hook Up The Signals signals.post_save.connect(post_save, model) signals.post_delete.connect(post_delete, model)
def post_save(sender, instance, created, *args, **kwargs): """ Apply any necessary pre-save moderation steps to new comments. """ key = get_model_key(instance) if key not in registry.keys(): return None document = registry[key](instance) # Could be a pain, but only way to make sure the index is updated. if document.is_indexable(instance): #Note adding and updating a document in solr uses the same command connection.add([document]) else: connection.delete([document])
def transform(self, value_or_model): self.value = get_model_key(value_or_model) return unicode(self)
def add(self, instance): from solango.models import IndexQueue model_key = get_model_key(instance) IndexQueue.objects.create(model_key=model_key, instance_id=instance.pk)
def index_instance(self, instance): key = get_model_key(instance) self.add(instance)