django haystack index update only new items

When solr index becomes bigger, update_index is taking some time and in this period search is returning empty resultset to prevent this basicly you only need to include to the index latest modified records in database.

following changes in your model and index structure help you to achieve fast index updates


models.py
class MyModel(models.Model):
    user = models.ForeignKey(User)
    modified = models.DateTimeField(auto_now=True) # add this field to your model
search_indexes.py
class MyModelIndex(SearchIndex):
    text = CharField(document=True, use_template=True)
    user = CharField(model_attr='user')

    # add this function to your search_indexes.py
    def get_updated_field(self):
        return "modified"
./manage.py update_index --age=110 
indexing will run only items updated in the last 110 hours.

Comments

Popular posts from this blog

Pyppeteer fix for BrowserError: Browser closed unexpectedly

overlay filesystem and containers

How to add pagination to django comments for your model