Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task/FP-982: Add rebuild_index haystack signal processor #189

Merged
merged 3 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions taccsite_cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def get_subdirs_as_module_names(path):

# Elasticsearch Indexing
HAYSTACK_ROUTERS = ['aldryn_search.router.LanguageRouter',]
HAYSTACK_SIGNAL_PROCESSOR = 'taccsite_cms.signal_processor.RealtimeSignalProcessor'
ALDRYN_SEARCH_DEFAULT_LANGUAGE = 'en'
ALDRYN_SEARCH_REGISTER_APPHOOK = True
HAYSTACK_CONNECTIONS = {
Expand Down
31 changes: 31 additions & 0 deletions taccsite_cms/signal_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from haystack.signals import BaseSignalProcessor
from django.db import models
from django.core.management import call_command
from cms import signals


class RealtimeSignalProcessor(BaseSignalProcessor):
"""
A signal processor to make a call to the Django Haystack
`rebuild_index` management command when a CMS document is
published, unpublished, or deleted. This will allow the
ElasticSearch index to remain up-to-date with the latest
published CMS content when a user searches the site.

Usage:
This signal processor hooks into Haystack via the
`HAYSTACK_SIGNAL_PROCESSOR` Django setting.
"""

def setup(self):
signals.post_publish.connect(self.handle_save)
signals.post_unpublish.connect(self.handle_save)
models.signals.post_delete.connect(self.handle_save)

def teardown(self):
signals.post_publish.disconnect(self.handle_save)
signals.post_unpublish.disconnect(self.handle_save)
models.signals.post_delete.disconnect(self.handle_save)

def handle_save(self, **kwargs):
call_command('rebuild_index', '--noinput')