Skip to content

Commit 62affb6

Browse files
authored
Merge pull request #114 from redmorello/main
Fixed XPATH error when multiple root nodes
2 parents 5ae6e1b + 3878ec3 commit 62affb6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Umbraco.Cms.Integrations.Search.Algolia/Controllers/SearchController.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Umbraco.Cms.Core.Routing;
88
using Umbraco.Cms.Core.Services;
99
using Umbraco.Cms.Core.Services.Implement;
10+
using Umbraco.Cms.Core.Web;
1011
using Umbraco.Cms.Integrations.Search.Algolia.Builders;
1112
using Umbraco.Cms.Integrations.Search.Algolia.Migrations;
1213
using Umbraco.Cms.Integrations.Search.Algolia.Models;
@@ -37,6 +38,8 @@ public class SearchController : UmbracoAuthorizedApiController
3738

3839
private readonly IAlgoliaSearchPropertyIndexValueFactory _algoliaSearchPropertyIndexValueFactory;
3940

41+
private readonly IUmbracoContextFactory _umbracoContextFactory;
42+
4043
public SearchController(
4144
IAlgoliaIndexService indexService,
4245
IAlgoliaSearchService<SearchResponse<Record>> searchService,
@@ -45,7 +48,8 @@ public SearchController(
4548
IUserService userService,
4649
IPublishedUrlProvider urlProvider,
4750
IContentService contentService,
48-
IAlgoliaSearchPropertyIndexValueFactory algoliaSearchPropertyIndexValueFactory)
51+
IAlgoliaSearchPropertyIndexValueFactory algoliaSearchPropertyIndexValueFactory,
52+
IUmbracoContextFactory umbracoContextFactory)
4953
{
5054
_indexService = indexService;
5155

@@ -62,6 +66,8 @@ public SearchController(
6266
_contentService = contentService;
6367

6468
_algoliaSearchPropertyIndexValueFactory = algoliaSearchPropertyIndexValueFactory;
69+
70+
_umbracoContextFactory = umbracoContextFactory;
6571
}
6672

6773
[HttpGet]
@@ -116,7 +122,9 @@ public async Task<IActionResult> BuildIndex([FromBody] IndexConfiguration indexC
116122

117123
foreach (var contentDataItem in indexContentData)
118124
{
119-
var contentItems = _umbracoHelper.ContentAtXPath($"//{contentDataItem.ContentType.Alias}");
125+
using var ctx = _umbracoContextFactory.EnsureUmbracoContext();
126+
var contentType = ctx.UmbracoContext.Content.GetContentType(contentDataItem.ContentType.Alias);
127+
var contentItems = ctx.UmbracoContext.Content.GetByContentType(contentType);
120128

121129
foreach (var contentItem in contentItems)
122130
{

0 commit comments

Comments
 (0)