Skip to content

Commit

Permalink
Merge pull request #20 from Kentico/feat/app-settings-configuration
Browse files Browse the repository at this point in the history
Feat/app settings configuration
  • Loading branch information
kentico-ericd authored Jun 9, 2022
2 parents 9f1c186 + 92a27ff commit 05c4982
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<add key="AlgoliaSearchDisableIndexing" value="true" />
```
### 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.
Expand Down
2 changes: 1 addition & 1 deletion src/Kentico.Xperience.AlgoliaSearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup>
<Title>Xperience Algolia Search</Title>
<PackageId>Kentico.Xperience.AlgoliaSearch</PackageId>
<Version>2.2.0</Version>
<Version>2.3.0</Version>
<Authors>Kentico Software</Authors>
<Company>Kentico Software</Company>
<PackageIcon>icon.png</PackageIcon>
Expand Down
15 changes: 12 additions & 3 deletions src/Services/Implementations/DefaultAlgoliaSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/// <summary>
/// Initializes a new instance of the <see cref="DefaultAlgoliaSearchService"/> class.
/// </summary>
public DefaultAlgoliaSearchService(ISearchClient searchClient)
public DefaultAlgoliaSearchService(ISearchClient searchClient, IAppSettingsService appSettingsService)
{
this.searchClient = searchClient;
this.appSettingsService = appSettingsService;
}


Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/Tests/IAlgoliaRegistrationServiceTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Algolia.Search.Clients;

using CMS.Core;
using CMS.DataEngine;
using CMS.DocumentEngine;
using CMS.SiteProvider;
Expand Down Expand Up @@ -30,9 +31,8 @@ internal class GetIndexSettingsTests : AlgoliaTests
public void GetIndexSettingsTests_SetUp()
{
var mockSearchClient = Substitute.For<ISearchClient>();
var algoliaSearchService = new DefaultAlgoliaSearchService(mockSearchClient);
var mockIndexService = Substitute.For<IAlgoliaIndexService>();
algoliaRegistrationService = new DefaultAlgoliaRegistrationService(algoliaSearchService, new MockEventLogService(), mockSearchClient, mockIndexService);
var algoliaSearchService = new DefaultAlgoliaSearchService(mockSearchClient, Substitute.For<IAppSettingsService>());
algoliaRegistrationService = new DefaultAlgoliaRegistrationService(algoliaSearchService, new MockEventLogService(), mockSearchClient, Substitute.For<IAlgoliaIndexService>());

var attributes = algoliaRegistrationService.GetAlgoliaIndexAttributes(Assembly.GetExecutingAssembly());
foreach (var attribute in attributes)
Expand Down
8 changes: 5 additions & 3 deletions tests/Tests/IAlgoliaSearchServiceTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -27,7 +29,7 @@ internal class GetFacetedAttributesTests : AlgoliaTests
[SetUp]
public void GetFacetedAttributesTests_SetUp()
{
algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For<ISearchClient>());
algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For<ISearchClient>(), Substitute.For<IAppSettingsService>());
}


Expand Down Expand Up @@ -149,7 +151,7 @@ internal class GetFilterablePropertyNameTests : AlgoliaTests
[SetUp]
public void GetFilterablePropertyNameTests_SetUp()
{
algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For<ISearchClient>());
algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For<ISearchClient>(), Substitute.For<IAppSettingsService>());
}


Expand Down Expand Up @@ -184,7 +186,7 @@ internal class OrderSearchablePropertiesTests : AlgoliaTests
[SetUp]
public void OrderSearchablePropertiesTests_SetUp()
{
algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For<ISearchClient>());
algoliaSearchService = new DefaultAlgoliaSearchService(Substitute.For<ISearchClient>(), Substitute.For<IAppSettingsService>());
}


Expand Down

0 comments on commit 05c4982

Please sign in to comment.