1
- using Umbraco . Cms . Core . Models ;
2
- using Umbraco . Cms . Core . Models . PublishedContent ;
1
+ using Microsoft . Extensions . Logging ;
2
+ using Umbraco . Cms . Core . Models ;
3
3
using Umbraco . Cms . Core . PropertyEditors ;
4
+ using Umbraco . Cms . Core . Services ;
4
5
using Umbraco . Cms . Integrations . Search . Algolia . Providers ;
5
6
6
7
namespace Umbraco . Cms . Integrations . Search . Algolia . Services
@@ -11,13 +12,23 @@ public class AlgoliaSearchPropertyIndexValueFactory : IAlgoliaSearchPropertyInde
11
12
12
13
private readonly ConverterCollection _converterCollection ;
13
14
15
+ private readonly IContentTypeService _contentTypeService ;
16
+
17
+ private readonly ILogger < AlgoliaSearchPropertyIndexValueFactory > _logger ;
18
+
14
19
public AlgoliaSearchPropertyIndexValueFactory (
15
20
PropertyEditorCollection propertyEditorCollection ,
16
- ConverterCollection converterCollection )
21
+ ConverterCollection converterCollection ,
22
+ IContentTypeService contentTypeService ,
23
+ ILogger < AlgoliaSearchPropertyIndexValueFactory > logger )
17
24
{
18
25
_propertyEditorsCollection = propertyEditorCollection ;
19
26
20
27
_converterCollection = converterCollection ;
28
+
29
+ _contentTypeService = contentTypeService ;
30
+
31
+ _logger = logger ;
21
32
}
22
33
23
34
public virtual KeyValuePair < string , object > GetValue ( IProperty property , string culture )
@@ -28,20 +39,36 @@ public virtual KeyValuePair<string, object> GetValue(IProperty property, string
28
39
return default ;
29
40
}
30
41
31
- var indexValues = propertyEditor . PropertyIndexValueFactory . GetIndexValues ( property , culture , null , true , Enumerable . Empty < string > ( ) , null ) ;
42
+ Dictionary < Guid , IContentType > contentTypeDictionary = _contentTypeService . GetAll ( ) . ToDictionary ( x => x . Key ) ;
43
+
44
+ try
45
+ {
46
+ var indexValues = propertyEditor . PropertyIndexValueFactory . GetIndexValues (
47
+ property ,
48
+ culture ,
49
+ null ,
50
+ true ,
51
+ Enumerable . Empty < string > ( ) ,
52
+ contentTypeDictionary ) ;
53
+
54
+ if ( indexValues == null || ! indexValues . Any ( ) ) return new KeyValuePair < string , object > ( property . Alias , string . Empty ) ;
32
55
33
- if ( indexValues == null || ! indexValues . Any ( ) ) return new KeyValuePair < string , object > ( property . Alias , string . Empty ) ;
56
+ var indexValue = indexValues . First ( ) ;
34
57
35
- var indexValue = indexValues . First ( ) ;
58
+ var converter = _converterCollection . FirstOrDefault ( p => p . Name == property . PropertyType . PropertyEditorAlias ) ;
59
+ if ( converter != null )
60
+ {
61
+ var result = converter . ParseIndexValues ( property , indexValue . Value ) ;
62
+ return new KeyValuePair < string , object > ( property . Alias , result ) ;
63
+ }
36
64
37
- var converter = _converterCollection . FirstOrDefault ( p => p . Name == property . PropertyType . PropertyEditorAlias ) ;
38
- if ( converter != null )
65
+ return new KeyValuePair < string , object > ( property . Alias , indexValue . Value ) ;
66
+ }
67
+ catch ( Exception ex )
39
68
{
40
- var result = converter . ParseIndexValues ( property , indexValue . Value ) ;
41
- return new KeyValuePair < string , object > ( property . Alias , result ) ;
69
+ _logger . LogError ( $ "Failed to get values for { property . Alias } : { ex . Message } " ) ;
70
+ return default ;
42
71
}
43
-
44
- return new KeyValuePair < string , object > ( property . Alias , indexValue . Value ) ;
45
72
}
46
73
}
47
74
}
0 commit comments