From 9982445979f4335f9b0a0abc2b7d2ecf681d8372 Mon Sep 17 00:00:00 2001 From: Sebastian Lees Date: Thu, 12 Sep 2024 13:09:58 +0100 Subject: [PATCH] ADDED enhanced indexing support for Page models. --- core/models.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ domestic/models.py | 8 ++++++++ 2 files changed, 58 insertions(+) diff --git a/core/models.py b/core/models.py index cb7ebe2492..c7b009df18 100644 --- a/core/models.py +++ b/core/models.py @@ -471,6 +471,12 @@ class Meta: layout_panels = [FieldPanel('template')] settings_panels = [FieldPanel('slug')] + Page.settings_panels + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('country_tags'), + index.SearchField('sector_tags'), + index.SearchField('type_of_export_tags'), + ] + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) field = self._meta.get_field('template') @@ -536,6 +542,12 @@ class TaggedPage(Page): ), ] + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('country_tags'), + index.SearchField('sector_tags'), + index.SearchField('type_of_export_tags'), + ] + @cached_classmethod def get_edit_handler(cls): # noqa panels = [ @@ -2239,6 +2251,15 @@ class Meta: review_reminder_sent = models.DateTimeField(blank=True, null=True) + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('page_title'), + index.SearchField('page_subheading'), + index.SearchField('page_teaser'), + index.SearchField('page_body'), + index.SearchField('cta_title'), + index.SearchField('cta_teaser'), + ] + def get_parent_page(self): current_page = self.specific parent_page = self.get_parent().specific @@ -2449,6 +2470,12 @@ class Meta: blank=True, ) + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('page_title'), + index.SearchField('page_teaser'), + index.SearchField('page_body'), + ] + class SupportTopicLandingPage(SeoMixin, cms_panels.SupportTopicLandingPanels, Page): template = 'domestic/contact/export-support/topic-landing.html' @@ -2494,6 +2521,12 @@ class Meta: blank=True, ) + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('page_title'), + index.SearchField('page_description'), + index.SearchField('page_body'), + ] + class GetInTouchPage(SeoMixin, cms_panels.GetInTouchPanels, Page): template = 'domestic/contact/export-support/get-in-touch.html' @@ -2530,6 +2563,12 @@ class Meta: blank=True, ) + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('page_title'), + index.SearchField('page_teaser'), + index.SearchField('page_body'), + ] + class TaskBasedCategoryPage(cms_panels.TaskBasedCategoryPage, Page): template = 'domestic/contact/export-support/task-based-category-page.html' @@ -2549,6 +2588,11 @@ class Meta: null=True, ) + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('page_title'), + index.SearchField('page_intro'), + ] + class TaskBasedSubCategoryPage(cms_panels.TaskBasedSubCategoryPage, Page): template = 'domestic/contact/export-support/task-based-sub-category-page.html' @@ -2582,6 +2626,12 @@ class Meta: blank=True, ) + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('page_title'), + index.SearchField('page_intro'), + index.SearchField('page_body'), + ] + @register_setting(icon='link-external') class ShareSettings(BaseSiteSetting): diff --git a/domestic/models.py b/domestic/models.py index 2a9fa4c7d1..a34f2948cd 100644 --- a/domestic/models.py +++ b/domestic/models.py @@ -27,6 +27,7 @@ from wagtail.images import get_image_model_string from wagtail.images.blocks import ImageChooserBlock from wagtail.models import Page +from wagtail.search import index from wagtail.snippets.blocks import SnippetChooserBlock from core import blocks as core_blocks, cache_keys, helpers, mixins, service_urls @@ -225,6 +226,13 @@ def get_absolute_url(self): path = self.get_url() return base_url + path if path else '' + search_fields = Page.search_fields + [ # Inherit search_fields from Page + index.SearchField('country_tags'), + index.SearchField('sector_tags'), + index.SearchField('region_tags'), + index.SearchField('type_of_export_tags'), + ] + class SocialLinksPageMixin(Page): """Abstract base class that adds social sharing links to the context