From e5565f7e9908f11c46b92e4533d24566b62ac571 Mon Sep 17 00:00:00 2001 From: Sean Wright Date: Mon, 16 May 2022 10:16:37 -0400 Subject: [PATCH 1/4] feat(lib): add app setting to disable search indexing --- README.md | 6 ++++++ .../DefaultAlgoliaSearchService.cs | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 98e0fb9..ba3caa1 100644 --- a/README.md +++ b/README.md @@ -1236,6 +1236,12 @@ While the Xperience Algolia integration works without any changes to the Xperien The imported module includes a setting under __Settings > Integration > Algolia search__ which allows you to enable/disable the indexing of your pages after they are created, updated, or deleted. Make sure to check that this setting is enabled after importing the module. +Indexing can also be disabled through App Settings by setting `AlgoliaSearchEnableIndexing` to `false`: + +```xml + +``` + ### Algolia search application The __Algolia search__ application provides a listing of all registered Algolia search model code files, along with some statistics directly from Algolia. By default, Algolia indexes are not rebuilt at any point - only updated and newly-created pages are indexed. To rebuild the index completely, use the circular arrow icon at the left of the grid. diff --git a/src/Services/Implementations/DefaultAlgoliaSearchService.cs b/src/Services/Implementations/DefaultAlgoliaSearchService.cs index 13339d9..7580c06 100644 --- a/src/Services/Implementations/DefaultAlgoliaSearchService.cs +++ b/src/Services/Implementations/DefaultAlgoliaSearchService.cs @@ -25,15 +25,18 @@ namespace Kentico.Xperience.AlgoliaSearch.Services public class DefaultAlgoliaSearchService : IAlgoliaSearchService { private readonly ISearchClient searchClient; - private const string KEY_INDEXING_ENABLED = "AlgoliaSearchEnableIndexing"; + private readonly IAppSettingsService appSettingsService; + private const string CMS_SETTINGS_KEY_INDEXING_ENABLED = "AlgoliaSearchEnableIndexing"; + private const string APP_SETTINGS_KEY_INDEXING_ENABLED = "AlgoliaSearchEnableIndexing"; /// /// Initializes a new instance of the class. /// - public DefaultAlgoliaSearchService(ISearchClient searchClient) + public DefaultAlgoliaSearchService(ISearchClient searchClient, IAppSettingsService appSettingsService) { this.searchClient = searchClient; + this.appSettingsService = appSettingsService; } @@ -144,7 +147,14 @@ public string GetFilterablePropertyName(PropertyInfo property) public bool IsIndexingEnabled() { - var existingKey = SettingsKeyInfoProvider.GetSettingsKeyInfo(KEY_INDEXING_ENABLED); + var indexingEnabled = ValidationHelper.GetBoolean(appSettingsService[APP_SETTINGS_KEY_INDEXING_ENABLED], true); + + if (!indexingEnabled) + { + return false; + } + + var existingKey = SettingsKeyInfoProvider.GetSettingsKeyInfo(CMS_SETTINGS_KEY_INDEXING_ENABLED); if (existingKey == null) { return true; From 6262bb571a0fe93d25ef991e604b0adbaf0de65d Mon Sep 17 00:00:00 2001 From: Sean Wright Date: Thu, 2 Jun 2022 17:04:38 -0400 Subject: [PATCH 2/4] refactor(lib): invert app setting key --- src/Services/Implementations/DefaultAlgoliaSearchService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Services/Implementations/DefaultAlgoliaSearchService.cs b/src/Services/Implementations/DefaultAlgoliaSearchService.cs index c6ec945..b40e378 100644 --- a/src/Services/Implementations/DefaultAlgoliaSearchService.cs +++ b/src/Services/Implementations/DefaultAlgoliaSearchService.cs @@ -27,7 +27,7 @@ internal class DefaultAlgoliaSearchService : IAlgoliaSearchService private readonly ISearchClient searchClient; private readonly IAppSettingsService appSettingsService; private const string CMS_SETTINGS_KEY_INDEXING_ENABLED = "AlgoliaSearchEnableIndexing"; - private const string APP_SETTINGS_KEY_INDEXING_ENABLED = "AlgoliaSearchEnableIndexing"; + private const string APP_SETTINGS_KEY_INDEXING_DISABLED = "AlgoliaSearchDisableIndexing"; /// @@ -147,9 +147,9 @@ public string GetFilterablePropertyName(PropertyInfo property) public bool IsIndexingEnabled() { - var indexingEnabled = ValidationHelper.GetBoolean(appSettingsService[APP_SETTINGS_KEY_INDEXING_ENABLED], true); + var indexingDisabled = ValidationHelper.GetBoolean(appSettingsService[APP_SETTINGS_KEY_INDEXING_DISABLED], false); - if (!indexingEnabled) + if (indexingDisabled) { return false; } From 640c674aba675c014d8d1727b60dbdf4ae281dd2 Mon Sep 17 00:00:00 2001 From: "Sean G. Wright" Date: Thu, 2 Jun 2022 21:09:37 -0400 Subject: [PATCH 3/4] docs(README): disable indexing example --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 676b346..fbd95cd 100644 --- a/README.md +++ b/README.md @@ -1266,10 +1266,10 @@ While the Xperience Algolia integration works without any changes to the Xperien The imported module includes a setting under __Settings > Integration > Algolia search__ which allows you to enable/disable the indexing of your pages after they are created, updated, or deleted. Make sure to check that this setting is enabled after importing the module. -Indexing can also be disabled through App Settings by setting `AlgoliaSearchEnableIndexing` to `false`: +Indexing can also be disabled through App Settings by setting `AlgoliaSearchDisableIndexing` to `true`: ```xml - + ``` ### Algolia search application From 92a27ff2bf6c5de2187f8193d3c6b28ea69ff9d3 Mon Sep 17 00:00:00 2001 From: Eric Dugre Date: Thu, 9 Jun 2022 17:31:58 -0400 Subject: [PATCH 4/4] increment version, fix tests --- src/Kentico.Xperience.AlgoliaSearch.csproj | 2 +- .../Implementations/DefaultAlgoliaSearchService.cs | 1 - tests/Tests/IAlgoliaRegistrationServiceTests.cs | 6 +++--- tests/Tests/IAlgoliaSearchServiceTests.cs | 8 +++++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Kentico.Xperience.AlgoliaSearch.csproj b/src/Kentico.Xperience.AlgoliaSearch.csproj index 91b19cd..72ae4ea 100644 --- a/src/Kentico.Xperience.AlgoliaSearch.csproj +++ b/src/Kentico.Xperience.AlgoliaSearch.csproj @@ -9,7 +9,7 @@ Xperience Algolia Search Kentico.Xperience.AlgoliaSearch - 2.2.0 + 2.3.0 Kentico Software Kentico Software icon.png diff --git a/src/Services/Implementations/DefaultAlgoliaSearchService.cs b/src/Services/Implementations/DefaultAlgoliaSearchService.cs index b40e378..b7dc4de 100644 --- a/src/Services/Implementations/DefaultAlgoliaSearchService.cs +++ b/src/Services/Implementations/DefaultAlgoliaSearchService.cs @@ -148,7 +148,6 @@ public string GetFilterablePropertyName(PropertyInfo property) public bool IsIndexingEnabled() { var indexingDisabled = ValidationHelper.GetBoolean(appSettingsService[APP_SETTINGS_KEY_INDEXING_DISABLED], false); - if (indexingDisabled) { return false; diff --git a/tests/Tests/IAlgoliaRegistrationServiceTests.cs b/tests/Tests/IAlgoliaRegistrationServiceTests.cs index 77f286d..91880bc 100644 --- a/tests/Tests/IAlgoliaRegistrationServiceTests.cs +++ b/tests/Tests/IAlgoliaRegistrationServiceTests.cs @@ -1,5 +1,6 @@ using Algolia.Search.Clients; +using CMS.Core; using CMS.DataEngine; using CMS.DocumentEngine; using CMS.SiteProvider; @@ -30,9 +31,8 @@ internal class GetIndexSettingsTests : AlgoliaTests public void GetIndexSettingsTests_SetUp() { var mockSearchClient = Substitute.For(); - var algoliaSearchService = new DefaultAlgoliaSearchService(mockSearchClient); - var mockIndexService = Substitute.For(); - algoliaRegistrationService = new DefaultAlgoliaRegistrationService(algoliaSearchService, new MockEventLogService(), mockSearchClient, mockIndexService); + var algoliaSearchService = new DefaultAlgoliaSearchService(mockSearchClient, Substitute.For()); + algoliaRegistrationService = new DefaultAlgoliaRegistrationService(algoliaSearchService, new MockEventLogService(), mockSearchClient, Substitute.For()); var attributes = algoliaRegistrationService.GetAlgoliaIndexAttributes(Assembly.GetExecutingAssembly()); foreach (var attribute in attributes) diff --git a/tests/Tests/IAlgoliaSearchServiceTests.cs b/tests/Tests/IAlgoliaSearchServiceTests.cs index 3573a88..3ef7922 100644 --- a/tests/Tests/IAlgoliaSearchServiceTests.cs +++ b/tests/Tests/IAlgoliaSearchServiceTests.cs @@ -1,5 +1,7 @@ using Algolia.Search.Clients; +using CMS.Core; + using Kentico.Xperience.AlgoliaSearch.Attributes; using Kentico.Xperience.AlgoliaSearch.Models.Facets; using Kentico.Xperience.AlgoliaSearch.Services; @@ -27,7 +29,7 @@ internal class GetFacetedAttributesTests : AlgoliaTests [SetUp] public void GetFacetedAttributesTests_SetUp() { - algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For()); + algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For(), Substitute.For()); } @@ -149,7 +151,7 @@ internal class GetFilterablePropertyNameTests : AlgoliaTests [SetUp] public void GetFilterablePropertyNameTests_SetUp() { - algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For()); + algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For(), Substitute.For()); } @@ -184,7 +186,7 @@ internal class OrderSearchablePropertiesTests : AlgoliaTests [SetUp] public void OrderSearchablePropertiesTests_SetUp() { - algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For()); + algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For(), Substitute.For()); }