Skip to content

Commit 9f1c186

Browse files
Merge pull request #17 from Kentico/seangwright/master
Feature: Algolia ISearchIndex Customization
2 parents 073cb6c + d071f0a commit 9f1c186

21 files changed

+137
-62
lines changed

.vscode/settings.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"files.exclude": {
3+
"**/.git": true,
4+
"**/.svn": true,
5+
"**/.hg": true,
6+
"**/CVS": true,
7+
"**/.DS_Store": true
8+
},
9+
10+
"search.exclude": {
11+
"**/node_modules": true,
12+
"**/bower_components": true,
13+
"**/*.code-search": true,
14+
"**/bin": true,
15+
"**/obj": true
16+
},
17+
18+
"omnisharp.defaultLaunchSolution": "./XperienceAlgolia.sln",
19+
"omnisharp.enableImportCompletion": true
20+
}
Binary file not shown.

CMS/CMSModules/Kentico.Xperience.AlgoliaSearch/Pages/AlgoliaSearch_Preview.aspx.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using Algolia.Search.Clients;
2-
using Algolia.Search.Models.Search;
1+
using Algolia.Search.Models.Search;
2+
33
using CMS.Core;
44
using CMS.Helpers;
55

@@ -34,8 +34,8 @@ protected override void OnLoad(EventArgs e)
3434
string searchText = QueryHelper.GetString("searchtext", "");
3535
if (!string.IsNullOrEmpty(searchText))
3636
{
37-
var client = Service.Resolve<ISearchClient>();
38-
var searchIndex = client.InitIndex(indexName);
37+
var searchIndexService = Service.Resolve<IAlgoliaIndexService>();
38+
var searchIndex = searchIndexService.InitializeIndex(indexName);
3939
if (searchIndex == null)
4040
{
4141
ShowError("Error loading search index. Please check the Event Log for more details.");

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,21 @@ public string Thumbnail { get; set; }
311311

312312
## :mag_right: Implementing the search interface
313313

314-
You can use Algolia's [.NET API](https://www.algolia.com/doc/api-client/getting-started/what-is-the-api-client/csharp/?client=csharp), [JavaScript API](https://www.algolia.com/doc/api-client/getting-started/what-is-the-api-client/javascript/?client=javascript), or [InstantSearch.js](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/) to implement a search interface on your live site. The following example will help you with creating a search interface for .NET Core. In your Controllers, you can get a `SearchIndex` object by injecting the `ISearchClient` interface and calling the `InitIndex()` method on the client using your index's code name. Then, construct a `Query` to search the Algolia index. Algolia's pagination is zero-based, so in the Dancing Goat sample project we subtract 1 from the current page number:
314+
You can use Algolia's [.NET API](https://www.algolia.com/doc/api-client/getting-started/what-is-the-api-client/csharp/?client=csharp), [JavaScript API](https://www.algolia.com/doc/api-client/getting-started/what-is-the-api-client/javascript/?client=javascript), or [InstantSearch.js](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/) to implement a search interface on your live site. The following example will help you with creating a search interface for .NET Core. In your Controllers, you can get a `SearchIndex` object by injecting the `IAlgoliaIndexService` interface and calling the `InitializeIndex()` method on the client using your index's code name. Then, construct a `Query` to search the Algolia index. Algolia's pagination is zero-based, so in the Dancing Goat sample project we subtract 1 from the current page number:
315315

316316
```cs
317-
private readonly ISearchClient _searchClient;
317+
private readonly IAlgoliaIndexService _indexService;
318318

319-
public SearchController(ISearchClient searchClient)
319+
public SearchController(IAlgoliaIndexService indexService)
320320
{
321-
_searchClient = searchClient;
321+
_indexService = indexService;
322322
}
323323

324324
public ActionResult Search(string searchText, int page = DEFAULT_PAGE_NUMBER)
325325
{
326326
page = Math.Max(page, DEFAULT_PAGE_NUMBER);
327327

328-
var searchIndex = _searchClient.InitIndex(AlgoliaSiteSearchModel.IndexName);
328+
var searchIndex = _indexService.InitializeIndex(AlgoliaSiteSearchModel.IndexName);
329329
var query = new Query(searchText)
330330
{
331331
Page = page - 1,
@@ -552,7 +552,7 @@ As the search interface can be designed in multiple languages using Algolia's AP
552552
553553
The Dancing Goat store doesn't use search out-of-the-box, so first you need to hook it up to Algolia. In this example, the search model seen in [Determining which pages to index](#determining-which-pages-to-index) will be used.
554554
555-
1. Inject `ISearchClient` into the `CoffeesController` as shown in [this section](#mag_right-implementing-the-search-interface).
555+
1. Inject `IAlgoliaIndexService` into the `CoffeesController` as shown in [this section](#mag_right-implementing-the-search-interface).
556556
557557
2. In __CoffeesController.cs__, create a method that will perform a standard Algolia search. In the `Query.Filters` property, add a filter to only retrieve records where `ClassName` is `DancingGoatCore.Coffee.` You also specify which `Facets` you want to retrieve, but they are not used yet.
558558
@@ -571,7 +571,7 @@ private SearchResponse<AlgoliaSiteSearchModel> Search()
571571
Facets = facetsToRetrieve
572572
};
573573

574-
var searchIndex = _searchClient.InitIndex(AlgoliaSiteSearchModel.IndexName);
574+
var searchIndex = _indexService.InitializeIndex(AlgoliaSiteSearchModel.IndexName);
575575
return searchIndex.Search<AlgoliaSiteSearchModel>(query);
576576
}
577577
```
@@ -700,7 +700,7 @@ private SearchResponse<AlgoliaSiteSearchModel> Search(IAlgoliaFacetFilter filter
700700
Facets = facetsToRetrieve
701701
};
702702

703-
var searchIndex = _searchClient.InitIndex(AlgoliaSiteSearchModel.IndexName);
703+
var searchIndex = _indexService.InitializeIndex(AlgoliaSiteSearchModel.IndexName);
704704
return searchIndex.Search<AlgoliaSiteSearchModel>(query);
705705
}
706706
```
@@ -1256,7 +1256,7 @@ While the Xperience Algolia integration works without any changes to the Xperien
12561256
12571257
### Importing the custom module
12581258
1259-
1. Download the latest _Kentico.Xperience.AlgoliaSearch_ ZIP package in the [/CMS/CMSModules/Kentico.Xperience.AlgoliaSearch](/CMS/CMSModules/Kentico.Xperience.AlgoliaSearch) directory
1259+
1. Download the _Kentico.Xperience.AlgoliaSearch_ ZIP package by locating the latest "Custom module" [Release](https://github.com/Kentico/xperience-algolia/releases).
12601260
1. In the Xperience adminstration, open the __Sites__ application.
12611261
1. [Import](https://docs.xperience.io/deploying-websites/exporting-and-importing-sites/importing-a-site-or-objects) the downloaded package with the __Import files__ and __Import code files__ [settings](https://docs.xperience.io/deploying-websites/exporting-and-importing-sites/importing-a-site-or-objects#Importingasiteorobjects-Import-Objectselectionsettings) enabled.
12621262
1. Perform the [necessary steps](https://docs.xperience.io/deploying-websites/exporting-and-importing-sites/importing-a-site-or-objects#Importingasiteorobjects-Importingpackageswithfiles) to include the following imported folder in your project:

src/AlgoliaQueueWorker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public AlgoliaQueueWorker()
3636
/// <summary>
3737
/// Adds an <see cref="AlgoliaQueueItem"/> to the worker queue to be processed.
3838
/// </summary>
39-
/// <param name="updatedNode"></param>
39+
/// <param name="queueItem">The item to be added to the queue.</param>
4040
public static void EnqueueAlgoliaQueueItem(AlgoliaQueueItem queueItem)
4141
{
4242
if (queueItem == null || queueItem.Node == null || String.IsNullOrEmpty(queueItem.IndexName))

src/AlgoliaStartupExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class AlgoliaStartupExtensions
1818
/// Registers instances of <see cref="IInsightsClient"/> and <see cref="ISearchClient"/>
1919
/// with Dependency Injection.
2020
/// </summary>
21+
/// <param name="services">The service collection.</param>
2122
/// <param name="configuration">The application configuration.</param>
2223
public static IServiceCollection AddAlgolia(this IServiceCollection services, IConfiguration configuration)
2324
{

src/Kentico.Xperience.AlgoliaSearch.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PropertyGroup>
1010
<Title>Xperience Algolia Search</Title>
1111
<PackageId>Kentico.Xperience.AlgoliaSearch</PackageId>
12-
<Version>2.1.0</Version>
12+
<Version>2.2.0</Version>
1313
<Authors>Kentico Software</Authors>
1414
<Company>Kentico Software</Company>
1515
<PackageIcon>icon.png</PackageIcon>
@@ -21,6 +21,7 @@
2121
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2222
<GenerateDocumentationFile>true</GenerateDocumentationFile>
2323
<NoWarn>1591</NoWarn>
24+
<LangVersion>7.3</LangVersion>
2425
</PropertyGroup>
2526

2627
<PropertyGroup Condition=" $(Configuration) == 'Release' ">

src/Models/Facets/AlgoliaFacetFilterViewModel.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using Algolia.Search.Models.Search;
2-
3-
using Kentico.Xperience.AlgoliaSearch.Attributes;
1+
using Kentico.Xperience.AlgoliaSearch.Attributes;
42

53
using Microsoft.Extensions.Localization;
64

src/Models/Facets/IAlgoliaFacetFilter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IAlgoliaFacetFilter
1515
/// <summary>
1616
/// A collection of an Algolia index's faceted attributes and the available facets.
1717
/// </summary>
18-
public abstract AlgoliaFacetedAttribute[] FacetedAttributes
18+
AlgoliaFacetedAttribute[] FacetedAttributes
1919
{
2020
get;
2121
set;
@@ -28,7 +28,7 @@ public abstract AlgoliaFacetedAttribute[] FacetedAttributes
2828
/// </summary>
2929
/// <param name="searchModelType">The Algolia search model that is being used in
3030
/// the current query. If null, all facet filters will use the "OR" condition.</param>
31-
public string GetFilter(Type searchModelType = null);
31+
string GetFilter(Type searchModelType = null);
3232

3333

3434
/// <summary>

src/Services/IAlgoliaConnection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface IAlgoliaConnection
2323
/// or null.</exception>
2424
/// <exception cref="InvalidOperationException">Thrown if the search model is configured
2525
/// incorrectly or index settings cannot be loaded.</exception>
26-
public void Initialize(string indexName);
26+
void Initialize(string indexName);
2727

2828

2929
/// <summary>
@@ -33,7 +33,7 @@ public interface IAlgoliaConnection
3333
/// </summary>
3434
/// <param name="objectIds">The Algolia internal IDs of the records to delete.</param>
3535
/// <returns>The number of records deleted.</returns>
36-
public int DeleteRecords(IEnumerable<string> objectIds);
36+
int DeleteRecords(IEnumerable<string> objectIds);
3737

3838

3939
/// <summary>
@@ -44,7 +44,7 @@ public interface IAlgoliaConnection
4444
/// <remarks>Logs an error if there are issues loading the node data.</remarks>
4545
/// <param name="dataObjects">The objects to upsert into Algolia.</param>
4646
/// <returns>The number of objects processed.</returns>
47-
public int UpsertRecords(IEnumerable<JObject> dataObjects);
47+
int UpsertRecords(IEnumerable<JObject> dataObjects);
4848

4949

5050
/// <summary>
@@ -53,6 +53,6 @@ public interface IAlgoliaConnection
5353
/// </summary>
5454
/// <exception cref="InvalidOperationException">Thrown if a search model class is not
5555
/// found for the index.</exception>
56-
public void Rebuild();
56+
void Rebuild();
5757
}
5858
}

0 commit comments

Comments
 (0)