diff --git a/README.md b/README.md index b5212a3..fbd95cd 100644 --- a/README.md +++ b/README.md @@ -1266,6 +1266,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 `AlgoliaSearchDisableIndexing` to `true`: + +```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/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 967afd2..b7dc4de 100644 --- a/src/Services/Implementations/DefaultAlgoliaSearchService.cs +++ b/src/Services/Implementations/DefaultAlgoliaSearchService.cs @@ -25,15 +25,18 @@ namespace Kentico.Xperience.AlgoliaSearch.Services internal 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_DISABLED = "AlgoliaSearchDisableIndexing"; /// /// 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,13 @@ public string GetFilterablePropertyName(PropertyInfo property) public bool IsIndexingEnabled() { - var existingKey = SettingsKeyInfoProvider.GetSettingsKeyInfo(KEY_INDEXING_ENABLED); + var indexingDisabled = ValidationHelper.GetBoolean(appSettingsService[APP_SETTINGS_KEY_INDEXING_DISABLED], false); + if (indexingDisabled) + { + return false; + } + + var existingKey = SettingsKeyInfoProvider.GetSettingsKeyInfo(CMS_SETTINGS_KEY_INDEXING_ENABLED); if (existingKey == null) { return true; 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()); }