7
7
using Umbraco . Cms . Core . Routing ;
8
8
using Umbraco . Cms . Core . Services ;
9
9
using Umbraco . Cms . Core . Services . Implement ;
10
+ using Umbraco . Cms . Core . Web ;
10
11
using Umbraco . Cms . Integrations . Search . Algolia . Builders ;
11
12
using Umbraco . Cms . Integrations . Search . Algolia . Migrations ;
12
13
using Umbraco . Cms . Integrations . Search . Algolia . Models ;
@@ -37,6 +38,8 @@ public class SearchController : UmbracoAuthorizedApiController
37
38
38
39
private readonly IAlgoliaSearchPropertyIndexValueFactory _algoliaSearchPropertyIndexValueFactory ;
39
40
41
+ private readonly IUmbracoContextFactory _umbracoContextFactory ;
42
+
40
43
public SearchController (
41
44
IAlgoliaIndexService indexService ,
42
45
IAlgoliaSearchService < SearchResponse < Record > > searchService ,
@@ -45,7 +48,8 @@ public SearchController(
45
48
IUserService userService ,
46
49
IPublishedUrlProvider urlProvider ,
47
50
IContentService contentService ,
48
- IAlgoliaSearchPropertyIndexValueFactory algoliaSearchPropertyIndexValueFactory )
51
+ IAlgoliaSearchPropertyIndexValueFactory algoliaSearchPropertyIndexValueFactory ,
52
+ IUmbracoContextFactory umbracoContextFactory )
49
53
{
50
54
_indexService = indexService ;
51
55
@@ -62,6 +66,8 @@ public SearchController(
62
66
_contentService = contentService ;
63
67
64
68
_algoliaSearchPropertyIndexValueFactory = algoliaSearchPropertyIndexValueFactory ;
69
+
70
+ _umbracoContextFactory = umbracoContextFactory ;
65
71
}
66
72
67
73
[ HttpGet ]
@@ -116,7 +122,9 @@ public async Task<IActionResult> BuildIndex([FromBody] IndexConfiguration indexC
116
122
117
123
foreach ( var contentDataItem in indexContentData )
118
124
{
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 ) ;
120
128
121
129
foreach ( var contentItem in contentItems )
122
130
{
0 commit comments