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. Removing old ImageFields and FileFields when updating through admin by alejandro.alonso 2 weeks, 4 days ago
  2. REMOVE IMAGEFIELD ATTACHMENT IN DJANGO by timonweb 2 weeks, 1 day ago
  3. Model Hooks by jakecr 2 years, 4 months ago
  4. Automatic CRUD urls from your models... by codigodaniel 1 year, 4 months ago
  5. FileField / ImageField with a delete checkbox by tomZ 4 years, 6 months ago

Comments

jpic (on January 17, 2012):

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

#

(Forgotten your password?)