haystack auto update (forget about update_index)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
from haystack.sites import site
from django.db.models import signals

def add_to_search_index(sender, instance=None, **kwargs):
    try:
        index = site.get_index(instance.__class__)
    except:
        return
    
    index.backend.update(index, [instance])
signals.post_save.connect(add_to_search_index)

def delete_from_search_index(sender, instance=None, **kwargs):
    try:
        index = site.get_index(instance.__class__)
    except:
        return
    
    index.backend.remove(instance)
signals.post_delete.connect(delete_from_search_index)

More like this

  1. Ordered items in the database - alternative by Leonidas 5 years, 11 months ago
  2. AutoSlugField by callipeo 5 years, 5 months ago
  3. Setting distinction between development and public server by Archatas 6 years, 2 months ago
  4. db_dump.py - for dumpping and loading data from database by limodou 6 years, 2 months ago
  5. Simple file size from bytes to kb/mb/gb by bryanhelmig 3 years, 4 months ago

Comments

jpic (on January 17, 2012):

Don't use this snippet. Use RealTimeSearchIndex instead of SearchIndex.

#

(Forgotten your password?)