Mercurial > public > sg101
diff gpp/downloads/search_indexes.py @ 467:b910cc1460c8
Add the ability to conditionally add model instances to the search index on update. This is not perfect, as some instances should be deleted from the index if they are updated such that they should not be in the index anymore. Will think about and address that later.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 24 Jul 2011 18:12:20 +0000 |
parents | 79240675b903 |
children | 3b30286adba5 |
line wrap: on
line diff
--- a/gpp/downloads/search_indexes.py Sun Jul 24 02:35:17 2011 +0000 +++ b/gpp/downloads/search_indexes.py Sun Jul 24 18:12:20 2011 +0000 @@ -1,12 +1,12 @@ """Haystack search index for the downloads application.""" from haystack.indexes import * from haystack import site -from queued_search.indexes import QueuedSearchIndex +from custom_search import CondQueuedSearchIndex from downloads.models import Download -class DownloadIndex(QueuedSearchIndex): +class DownloadIndex(CondQueuedSearchIndex): text = CharField(document=True, use_template=True) author = CharField(model_attr='user') pub_date = DateTimeField(model_attr='date_added') @@ -17,5 +17,7 @@ def get_updated_field(self): return 'update_date' + def can_index(self, instance): + return instance.is_public site.register(Download, DownloadIndex)