I am using haystack in our django application for search and search is working very fine. But I am having an issue with reamtime search. For realtime search I am using haystack's default RealTimeSignalProcessor(haystack.signals.RealtimeSignalProcessor). My model contains one many to many field in it. When data is changed for this many to many field only, it seems the realtimesignal processor is not updating indexing data properly. After updating the many to many data, I am getting wrong search result.
Its working after manually running rebuild_index command. I think rebuild_index is working because its doing cleaning first and then again building indexing data.
Can someone suggest some solution to the problem ?
By the way following is code around it.
Model:
class Message_forum(models.Model):
message = models.ForeignKey(Message)
tags = models.ManyToManyField(Tag, blank=True, null=True) #this is many to many field
search_index.py:
class Message_forumIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
message = indexes.CharField(model_attr='message', null=True)
tags = indexes.CharField(model_attr='tags', null=True)
def get_model(self):
return Message_forum
def index_queryset(self, using=None):
return self.get_model().objects.all()
def prepare_tags(self, obj):
return [tag.tag for tag in obj.tags.all()]
index template:
{{ object.tags.tag }}
settings.py:
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
I am having latest version of haystack and whoosh as back-end.