Skip to content

Commit

Permalink
Merge pull request #8468 from cfpb/fix/search-index-updates
Browse files Browse the repository at this point in the history
Fix search index updates for AbstractFilterPages
  • Loading branch information
chosak committed Jun 14, 2024
2 parents 9514f54 + 01f8b26 commit 3f573de
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
28 changes: 17 additions & 11 deletions cfgov/search/elasticsearch_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,28 @@ class WagtailSignalProcessor(BaseSignalProcessor):
Wagtail events and calls the appropriate signals to update the search
index.
It also translates the `instance` object that gets passed by Wagtail
signal handlers into its `instance.specific` equivalent for any
downstream logic that depends on the specific page type.
It also translates the `instance` Page object that gets passed by Wagtail
signal handlers into its AbstractFilterPage equivalent (if it so inherits)
to ensure that the filterable page search index is properly updated.
"""

def handle_delete(self, sender, instance, **kwargs):
if isinstance(instance, Page):
instance = instance.specific
def check_afp(self, instance):
# If the provided instance is a Wagtail page instance that inherits
# from AbstractFilterPage, convert it to an AFP instance.
from v1.models import AbstractFilterPage

super().handle_delete(sender, instance, **kwargs)
if isinstance(instance, Page) and issubclass(
instance.specific_class, AbstractFilterPage
):
instance = AbstractFilterPage.objects.get(pk=instance.pk)

def handle_save(self, sender, instance, **kwargs):
if isinstance(instance, Page):
instance = instance.specific
return instance

super().handle_save(sender, instance, **kwargs)
def handle_delete(self, sender, instance, **kwargs):
super().handle_delete(sender, self.check_afp(instance), **kwargs)

def handle_save(self, sender, instance, **kwargs):
super().handle_save(sender, self.check_afp(instance), **kwargs)

def setup(self):
page_published.connect(self.handle_save)
Expand Down
6 changes: 6 additions & 0 deletions cfgov/v1/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class FilterablePagesDocument(Document):
products = fields.KeywordField()
content = fields.TextField()

def update(self, thing, *args, **kwargs):
if isinstance(thing, AbstractFilterPage):
thing = thing.specific

return super().update(thing, *args, **kwargs)

def get_queryset(self, *args, **kwargs):
return AbstractFilterPage.objects.live().public().specific()

Expand Down

0 comments on commit 3f573de

Please sign in to comment.