Add AUTO_UPDATE option to backend parameters

By default, Wagtail will keep all search indexes up to date using signal handlers.

This is sometimes not needed/wanted. This PR allows auto-update to be configured on a per-index basis.
This commit is contained in:
Karl Hobley 2015-05-27 16:31:21 +01:00
parent 640383ad29
commit 72db917ddc
2 changed files with 7 additions and 4 deletions

View file

@ -51,9 +51,12 @@ def get_search_backend(backend='default', **kwargs):
return backend_cls(params)
def get_search_backends():
def get_search_backends(with_auto_update=False):
if hasattr(settings, 'WAGTAILSEARCH_BACKENDS'):
for backend in settings.WAGTAILSEARCH_BACKENDS.keys():
for backend, params in settings.WAGTAILSEARCH_BACKENDS.items():
if with_auto_update and params.get('AUTO_UPDATE', True) is False:
continue
yield get_search_backend(backend)
else:
yield get_search_backend('default')

View file

@ -20,7 +20,7 @@ def post_save_signal_handler(instance, **kwargs):
indexed_instance = get_indexed_instance(instance)
if indexed_instance:
for backend in get_search_backends():
for backend in get_search_backends(with_auto_update=True):
backend.add(indexed_instance)
@ -28,7 +28,7 @@ def post_delete_signal_handler(instance, **kwargs):
indexed_instance = get_indexed_instance(instance)
if indexed_instance:
for backend in get_search_backends():
for backend in get_search_backends(with_auto_update=True):
backend.delete(indexed_instance)