From dee1bb0e3b141cd38ac0c24dc856bd5f55db51d6 Mon Sep 17 00:00:00 2001 From: David Henne Date: Fri, 13 Aug 2021 16:29:22 -0500 Subject: [PATCH 1/9] short fix: hardcode parallax and slideshow values to exclude from search --- castle/cms/browser/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index 31db3d4c9..685488de9 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -61,7 +61,7 @@ def options(self): ptypes = api.portal.get_tool('portal_types') allow_anyway = ['Audio'] for type_id in ptypes.objectIds(): - if type_id in ('Link', 'Document', 'Folder'): + if type_id in ('Link', 'Document', 'Folder', 'Parallax', 'Slideshow'): continue _type = ptypes[type_id] if not _type.global_allow and type_id not in allow_anyway: From 00f9c9a2d8d33c78e183471c6ba1583cc00d1955 Mon Sep 17 00:00:00 2001 From: David Henne Date: Fri, 13 Aug 2021 16:32:02 -0500 Subject: [PATCH 2/9] Create Castle control panel to select which content items will be excluded from searches --- castle/cms/browser/controlpanel/settings.py | 8 ++++++- castle/cms/configure.zcml | 4 ++++ castle/cms/interfaces/__init__.py | 1 + castle/cms/interfaces/controlpanel.py | 21 +++++++++++++++++-- castle/cms/profiles/3002/metadata.xml | 4 ++++ .../profiles/3002/registry/controlpanel.xml | 6 ++++++ castle/cms/profiles/default/metadata.xml | 2 +- .../default/registry/controlpanel.xml | 14 +++++++++++++ castle/cms/upgrades.zcml | 15 +++++++++++++ castle/cms/upgrades/__init__.py | 1 + castle/cms/vocabularies.py | 17 +++++++++++++++ 11 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 castle/cms/profiles/3002/metadata.xml create mode 100644 castle/cms/profiles/3002/registry/controlpanel.xml diff --git a/castle/cms/browser/controlpanel/settings.py b/castle/cms/browser/controlpanel/settings.py index 42387486a..b495b4e27 100644 --- a/castle/cms/browser/controlpanel/settings.py +++ b/castle/cms/browser/controlpanel/settings.py @@ -6,6 +6,7 @@ IContentSettings, ISiteConfiguration, ISearchSettings, + ISearchExclusionSettings, IElasticSearchSettings, ISlideshowSettings, ) @@ -46,6 +47,11 @@ class ElasticForm(group.GroupForm): fields = field.Fields(IElasticSearchSettings) +class SearchExclusionForm(group.GroupForm): + label = u"Search Settings" + fields = field.Fields(ISearchExclusionSettings) + + class CastleSettingsControlPanelForm(controlpanel.RegistryEditForm): id = "CastleSettingsControlPanel" @@ -54,7 +60,7 @@ class CastleSettingsControlPanelForm(controlpanel.RegistryEditForm): schema = ICastleSettings schema_prefix = "castle" fields = field.Fields(ISiteConfiguration) - groups = (APIForm, ArchivalForm, ContentForm, ConfigurableTextForm, ElasticForm) + groups = (APIForm, ArchivalForm, ContentForm, ConfigurableTextForm, ElasticForm, SearchExclusionForm) def updateFields(self): super(CastleSettingsControlPanelForm, self).updateFields() diff --git a/castle/cms/configure.zcml b/castle/cms/configure.zcml index 7b4b67a1a..3b5acfe95 100644 --- a/castle/cms/configure.zcml +++ b/castle/cms/configure.zcml @@ -131,6 +131,10 @@ component=".vocabularies.ProvidesTitleSummaryLeadImageVocabularyFactory" name="castle.cms.vocabularies.ProvidesTitleSummaryLeadImage" /> + + + 3002 + \ No newline at end of file diff --git a/castle/cms/profiles/3002/registry/controlpanel.xml b/castle/cms/profiles/3002/registry/controlpanel.xml new file mode 100644 index 000000000..6354addae --- /dev/null +++ b/castle/cms/profiles/3002/registry/controlpanel.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/castle/cms/profiles/default/metadata.xml b/castle/cms/profiles/default/metadata.xml index 31f8e8bbf..fcc13a3ec 100644 --- a/castle/cms/profiles/default/metadata.xml +++ b/castle/cms/profiles/default/metadata.xml @@ -1,6 +1,6 @@ - 3001 + 3002 profile-plone.app.querystring:default profile-plone.app.mosaic:default diff --git a/castle/cms/profiles/default/registry/controlpanel.xml b/castle/cms/profiles/default/registry/controlpanel.xml index 0d3f2b4cf..fb36915ba 100644 --- a/castle/cms/profiles/default/registry/controlpanel.xml +++ b/castle/cms/profiles/default/registry/controlpanel.xml @@ -22,6 +22,8 @@ prefix="castle" /> + @@ -132,4 +134,16 @@ + + + + + + + + diff --git a/castle/cms/upgrades.zcml b/castle/cms/upgrades.zcml index 0cdf49d60..9283cbf82 100644 --- a/castle/cms/upgrades.zcml +++ b/castle/cms/upgrades.zcml @@ -513,4 +513,19 @@ handler=".upgrades.upgrade_3001" profile="castle.cms:default" /> + + diff --git a/castle/cms/upgrades/__init__.py b/castle/cms/upgrades/__init__.py index 4becfda3d..1de6f5e0e 100644 --- a/castle/cms/upgrades/__init__.py +++ b/castle/cms/upgrades/__init__.py @@ -72,3 +72,4 @@ def upgrade(context, logger=None): upgrade_3000 = default_upgrade_factory('3000') upgrade_3001 = default_upgrade_factory('3001') +upgrade_3002 = default_upgrade_factory('3002') diff --git a/castle/cms/vocabularies.py b/castle/cms/vocabularies.py index 480d7ed55..843cfef74 100644 --- a/castle/cms/vocabularies.py +++ b/castle/cms/vocabularies.py @@ -124,6 +124,23 @@ def __call__(self, context): LocationsVocabulary = LocationsVocabularyFactory() +@implementer(IVocabularyFactory) +class SiteTypesVocabularyFactory(object): + + def __call__(self, context): + site = getSite() + portal_types = getToolByName(site, "portal_types") + types = portal_types.listContentTypes() + terms = [] + for type in types: + terms.append(SimpleVocabulary.createTerm(type, type, type)) + + return SimpleVocabulary(terms) + + +SiteTypesVocabulary = SiteTypesVocabularyFactory() + + @implementer(IVocabularyFactory) class MimeTypeVocabularyFactory(object): From 2a30099f92b682d8f8fd4dd0dcb890f75208b30d Mon Sep 17 00:00:00 2001 From: David Henne Date: Mon, 16 Aug 2021 09:27:17 -0500 Subject: [PATCH 3/9] Get control panel values to filter search types. --- castle/cms/browser/controlpanel/settings.py | 1 + castle/cms/browser/search.py | 7 ++++++- castle/cms/profiles/3002/metadata.xml | 2 +- castle/cms/profiles/3002/registry/controlpanel.xml | 2 +- castle/cms/profiles/default/registry/controlpanel.xml | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/castle/cms/browser/controlpanel/settings.py b/castle/cms/browser/controlpanel/settings.py index b495b4e27..276a80faa 100644 --- a/castle/cms/browser/controlpanel/settings.py +++ b/castle/cms/browser/controlpanel/settings.py @@ -68,6 +68,7 @@ def updateFields(self): self.groups[1].fields['archival_types_to_archive'].widgetFactory = SelectFieldWidget self.groups[1].fields['archival_states_to_archive'].widgetFactory = SelectFieldWidget self.groups[2].fields['file_upload_fields'].widgetFactory = FileUploadFieldsFieldWidget + self.groups[5].fields['items_to_exclude'].widgetFactory = SelectFieldWidget def update(self): super(CastleSettingsControlPanelForm, self).update() diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index 685488de9..dcd9ede91 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -58,10 +58,15 @@ def options(self): } }] + registry = getUtility(IRegistry) + exclude_types_from_search = registry.get('castle.exclude_from_searches') + excluded_content = [] + if exclude_types_from_search: + excluded_content = registry.get('castle.items_to_exclude') ptypes = api.portal.get_tool('portal_types') allow_anyway = ['Audio'] for type_id in ptypes.objectIds(): - if type_id in ('Link', 'Document', 'Folder', 'Parallax', 'Slideshow'): + if type_id in excluded_content: continue _type = ptypes[type_id] if not _type.global_allow and type_id not in allow_anyway: diff --git a/castle/cms/profiles/3002/metadata.xml b/castle/cms/profiles/3002/metadata.xml index eeec2ef26..ef6a776a9 100644 --- a/castle/cms/profiles/3002/metadata.xml +++ b/castle/cms/profiles/3002/metadata.xml @@ -1,4 +1,4 @@ 3002 - \ No newline at end of file + diff --git a/castle/cms/profiles/3002/registry/controlpanel.xml b/castle/cms/profiles/3002/registry/controlpanel.xml index 6354addae..38880330a 100644 --- a/castle/cms/profiles/3002/registry/controlpanel.xml +++ b/castle/cms/profiles/3002/registry/controlpanel.xml @@ -3,4 +3,4 @@ i18n:domain="plone"> - \ No newline at end of file + diff --git a/castle/cms/profiles/default/registry/controlpanel.xml b/castle/cms/profiles/default/registry/controlpanel.xml index fb36915ba..806f39684 100644 --- a/castle/cms/profiles/default/registry/controlpanel.xml +++ b/castle/cms/profiles/default/registry/controlpanel.xml @@ -143,7 +143,7 @@ - + From 3f50ef1b15df410ad8f706b8244a45805987ac52 Mon Sep 17 00:00:00 2001 From: David Henne Date: Tue, 30 Nov 2021 17:17:38 -0600 Subject: [PATCH 4/9] combine search exclusion views. --- .../cms/browser/controlpanel/configure.zcml | 2 +- castle/cms/browser/controlpanel/search.py | 31 ++++++++++++++++++- castle/cms/browser/controlpanel/settings.py | 9 +----- .../templates/search-exclusion.pt | 9 ++++++ castle/cms/interfaces/controlpanel.py | 6 ++-- .../{controlpanel.xml => registry.xml} | 5 ++- .../default/registry/controlpanel.xml | 4 +-- 7 files changed, 48 insertions(+), 18 deletions(-) rename castle/cms/profiles/3002/registry/{controlpanel.xml => registry.xml} (79%) diff --git a/castle/cms/browser/controlpanel/configure.zcml b/castle/cms/browser/controlpanel/configure.zcml index ea17f9308..f4e138a25 100644 --- a/castle/cms/browser/controlpanel/configure.zcml +++ b/castle/cms/browser/controlpanel/configure.zcml @@ -142,7 +142,7 @@ +

View Title

+

Excluded content

This is a list of items with "Exclude From Search" selected in their properties. You can click on an item to navigate and edit that property if you'd like it to show up in search results.

${item/Title}

+

+

Exclude by type

+ Content can be excluded from searches by type. Adding to the list below will make all content of that type not show up in search results. +

+
+ +
\ No newline at end of file diff --git a/castle/cms/interfaces/controlpanel.py b/castle/cms/interfaces/controlpanel.py index 41b42c3f2..43f03a8f7 100644 --- a/castle/cms/interfaces/controlpanel.py +++ b/castle/cms/interfaces/controlpanel.py @@ -538,12 +538,12 @@ class IElasticSearchSettings(Interface): class ISearchExclusionSettings(Interface): exclude_from_searches = schema.Bool( - title=u"Exclude selected items from searches", + title=u"Exclude content type from searches", default=False ) items_to_exclude = schema.List( - title=u'Items To Exclude', + title=u'Content To Exclude', required=False, default=[], value_type=schema.Choice( @@ -575,7 +575,7 @@ class IAdjustableFontSizeSettings(Interface): class ICastleSettings(ISiteConfiguration, IAPISettings, IArchivalSettings, IContentSettings, - ISearchSettings, ISearchExclusionSettings, + ISearchSettings, IElasticSearchSettings, ISlideshowSettings, IAdjustableFontSizeSettings): pass diff --git a/castle/cms/profiles/3002/registry/controlpanel.xml b/castle/cms/profiles/3002/registry/registry.xml similarity index 79% rename from castle/cms/profiles/3002/registry/controlpanel.xml rename to castle/cms/profiles/3002/registry/registry.xml index 38880330a..9fd88cc63 100644 --- a/castle/cms/profiles/3002/registry/controlpanel.xml +++ b/castle/cms/profiles/3002/registry/registry.xml @@ -1,6 +1,5 @@ - - + + \ No newline at end of file diff --git a/castle/cms/profiles/default/registry/controlpanel.xml b/castle/cms/profiles/default/registry/controlpanel.xml index 806f39684..8a1be2416 100644 --- a/castle/cms/profiles/default/registry/controlpanel.xml +++ b/castle/cms/profiles/default/registry/controlpanel.xml @@ -135,13 +135,13 @@ From 07490b9da017f1167e46b7a0eec52603028f3df5 Mon Sep 17 00:00:00 2001 From: David Henne Date: Tue, 30 Nov 2021 17:19:38 -0600 Subject: [PATCH 5/9] flake --- castle/cms/browser/controlpanel/templates/search-exclusion.pt | 2 +- castle/cms/profiles/3002/registry/registry.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/castle/cms/browser/controlpanel/templates/search-exclusion.pt b/castle/cms/browser/controlpanel/templates/search-exclusion.pt index 25919f6da..10a9c1f9f 100644 --- a/castle/cms/browser/controlpanel/templates/search-exclusion.pt +++ b/castle/cms/browser/controlpanel/templates/search-exclusion.pt @@ -21,4 +21,4 @@ - \ No newline at end of file + diff --git a/castle/cms/profiles/3002/registry/registry.xml b/castle/cms/profiles/3002/registry/registry.xml index 9fd88cc63..335bc6b60 100644 --- a/castle/cms/profiles/3002/registry/registry.xml +++ b/castle/cms/profiles/3002/registry/registry.xml @@ -2,4 +2,4 @@ - \ No newline at end of file + From 182107d499a85aef5f8e4a43a26a0486e2c35c31 Mon Sep 17 00:00:00 2001 From: David Henne Date: Thu, 2 Dec 2021 15:06:12 -0600 Subject: [PATCH 6/9] constrain types allowed for catalog query --- castle/cms/browser/search.py | 26 ++++++++++++++++--- .../default/registry/controlpanel.xml | 14 ---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index dcd9ede91..8c47de111 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -1,4 +1,5 @@ from castle.cms.interfaces import ICrawlerConfiguration +from castle.cms.interfaces.controlpanel import ISearchExclusionSettings from castle.cms.utils import get_public_url from collective.elasticsearch.es import ElasticSearchCatalog from collective.elasticsearch.interfaces import IQueryAssembler @@ -59,10 +60,13 @@ def options(self): }] registry = getUtility(IRegistry) - exclude_types_from_search = registry.get('castle.exclude_from_searches') + settings = registry.forInterface(ISearchExclusionSettings) + exclude_types_from_search = settings.exclude_from_searches excluded_content = [] + if exclude_types_from_search: - excluded_content = registry.get('castle.items_to_exclude') + excluded_content = settings.items_to_exclude or [] + ptypes = api.portal.get_tool('portal_types') allow_anyway = ['Audio'] for type_id in ptypes.objectIds(): @@ -88,7 +92,6 @@ def options(self): # search_types.sort(key=lambda type: type['label']) additional_sites = [] - registry = getUtility(IRegistry) settings = registry.forInterface( ICrawlerConfiguration, prefix='castle') if settings.crawler_active and settings.crawler_site_maps: @@ -202,6 +205,9 @@ def __call__(self): query['has_private_parents'] = False query['exclude_from_search'] = False + allowed_types = self.get_allowed_types() + query['portal_type'] = allowed_types + try: page_size = int(self.request.form.get('pageSize')) except Exception: @@ -251,6 +257,20 @@ def get_results(self, page, page_size, query): 'suggestions': [] }, default=custom_json_handler) + def get_allowed_types(self): + registry = getUtility(IRegistry) + settings = registry.forInterface(ISearchExclusionSettings) + exclude_types_from_search = settings.exclude_from_searches + excluded_content = [] + + if exclude_types_from_search: + excluded_content = settings.items_to_exclude or [] + + ptypes = api.portal.get_tool('portal_types') + allowed_types = [type for type in ptypes.objectIds() if type not in excluded_content] + + return tuple(allowed_types) + def get_es_results(self, page, page_size, query): start = (page - 1) * page_size site_path = '/'.join(self.context.getPhysicalPath()) diff --git a/castle/cms/profiles/default/registry/controlpanel.xml b/castle/cms/profiles/default/registry/controlpanel.xml index 8a1be2416..0d3f2b4cf 100644 --- a/castle/cms/profiles/default/registry/controlpanel.xml +++ b/castle/cms/profiles/default/registry/controlpanel.xml @@ -22,8 +22,6 @@ prefix="castle" /> - @@ -134,16 +132,4 @@ - - - - - - - - From ea9b44c4e35c37fe9557ef09ad5ac21072764fde Mon Sep 17 00:00:00 2001 From: Adam McNevin Date: Tue, 19 Mar 2024 10:17:36 -1000 Subject: [PATCH 7/9] Fix filtering and upgrade profile --- castle/cms/browser/search.py | 16 +++++++++ .../cms/profiles/{3002 => 3014}/metadata.xml | 2 +- .../{3002 => 3014}/registry/registry.xml | 0 castle/cms/upgrades.zcml | 33 +++++++++---------- castle/cms/upgrades/__init__.py | 3 +- 5 files changed, 35 insertions(+), 19 deletions(-) rename castle/cms/profiles/{3002 => 3014}/metadata.xml (63%) rename castle/cms/profiles/{3002 => 3014}/registry/registry.xml (100%) diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index 1c2221283..c544cdf92 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -172,6 +172,8 @@ def __call__(self): query['has_private_parents'] = False query['exclude_from_search'] = False + print('=== searchajax ===') + print(self) allowed_types = self.get_allowed_types() query['portal_type'] = allowed_types @@ -189,6 +191,20 @@ def __call__(self): return self.get_hps_results(page, page_size, query) else: return self.get_results(page, page_size, query) + + def get_allowed_types(self): + registry = getUtility(IRegistry) + settings = registry.forInterface(ISearchExclusionSettings) + exclude_types_from_search = settings.exclude_from_searches + excluded_content = [] + + if exclude_types_from_search: + excluded_content = settings.items_to_exclude or [] + + ptypes = api.portal.get_tool('portal_types') + allowed_types = [type for type in ptypes.objectIds() if type not in excluded_content] + + return tuple(allowed_types) def get_results(self, page, page_size, query): # regular plone search diff --git a/castle/cms/profiles/3002/metadata.xml b/castle/cms/profiles/3014/metadata.xml similarity index 63% rename from castle/cms/profiles/3002/metadata.xml rename to castle/cms/profiles/3014/metadata.xml index ef6a776a9..80986008e 100644 --- a/castle/cms/profiles/3002/metadata.xml +++ b/castle/cms/profiles/3014/metadata.xml @@ -1,4 +1,4 @@ - 3002 + 3014 diff --git a/castle/cms/profiles/3002/registry/registry.xml b/castle/cms/profiles/3014/registry/registry.xml similarity index 100% rename from castle/cms/profiles/3002/registry/registry.xml rename to castle/cms/profiles/3014/registry/registry.xml diff --git a/castle/cms/upgrades.zcml b/castle/cms/upgrades.zcml index 201a3e2a2..66778414e 100644 --- a/castle/cms/upgrades.zcml +++ b/castle/cms/upgrades.zcml @@ -37,23 +37,6 @@ profile="castle.cms:default" /> - - - - + + + diff --git a/castle/cms/upgrades/__init__.py b/castle/cms/upgrades/__init__.py index 7dd36722c..0e22891b3 100644 --- a/castle/cms/upgrades/__init__.py +++ b/castle/cms/upgrades/__init__.py @@ -49,7 +49,6 @@ def upgrade(context, logger=None): upgrade_3000 = default_upgrade_factory('3000') upgrade_3001 = default_upgrade_factory('3001') -upgrade_3002 = default_upgrade_factory('3002') upgrade_3003 = default_upgrade_factory('3003') upgrade_3004 = default_upgrade_factory('3004') @@ -138,3 +137,5 @@ def upgrade_3011(site, logger=CASTLE_LOGGER): upgrade_3012 = default_upgrade_factory('3012') + +upgrade_3014 = default_upgrade_factory('3014') From 6e6f74340c4363d338515f01c12ea077ac89d675 Mon Sep 17 00:00:00 2001 From: Adam McNevin Date: Wed, 27 Mar 2024 09:10:45 -1000 Subject: [PATCH 8/9] Remove fluff --- castle/cms/browser/search.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index c544cdf92..b52859f6a 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -172,8 +172,6 @@ def __call__(self): query['has_private_parents'] = False query['exclude_from_search'] = False - print('=== searchajax ===') - print(self) allowed_types = self.get_allowed_types() query['portal_type'] = allowed_types From c2b42da2b185203fb281aaec29cb78020020a2a6 Mon Sep 17 00:00:00 2001 From: Adam McNevin Date: Wed, 27 Mar 2024 11:25:02 -1000 Subject: [PATCH 9/9] Prevent all portal types from being added to every search --- castle/cms/browser/search.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/castle/cms/browser/search.py b/castle/cms/browser/search.py index b52859f6a..204636a6e 100644 --- a/castle/cms/browser/search.py +++ b/castle/cms/browser/search.py @@ -172,7 +172,7 @@ def __call__(self): query['has_private_parents'] = False query['exclude_from_search'] = False - allowed_types = self.get_allowed_types() + allowed_types = self.get_allowed_types(query) query['portal_type'] = allowed_types try: @@ -190,7 +190,13 @@ def __call__(self): else: return self.get_results(page, page_size, query) - def get_allowed_types(self): + def get_allowed_types(self, query): + # If a filter tab is selected, use that portal type only + portal_types = query.get('portal_type') + if portal_types is not None: + return portal_types + + # Otherwise, use all non-excluded portal types registry = getUtility(IRegistry) settings = registry.forInterface(ISearchExclusionSettings) exclude_types_from_search = settings.exclude_from_searches