Was.OrcSearch – Diff between revs 1 and 4
?pathlinks?
Rev 1 | Rev 4 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | using System; |
1 | using System; |
|
- | 2 | using System.Collections; |
||
2 | using System.Collections.Generic; |
3 | using System.Collections.Generic; |
|
- | 4 | using System.ComponentModel; |
||
- | 5 | using System.Linq; |
||
3 | using System.Reflection; |
6 | using System.Reflection; |
|
- | 7 | using System.Threading; |
||
4 | using Was.OrcSearch.Attributes; |
8 | using Was.OrcSearch.Attributes; |
|
5 | using Was.OrcSearch.Models; |
9 | using Was.OrcSearch.Models; |
|
6 | using Was.OrcSearch.Models.Interfaces; |
10 | using Was.OrcSearch.Models.Interfaces; |
|
Line 7... | Line 11... | |||
7 | |
11 | |
|
8 | namespace Was.OrcSearch.Metadata |
12 | namespace Was.OrcSearch.Metadata |
|
9 | { |
13 | { |
|
10 | public class AttributeMetadataCollection : ReflectionMetadataCollection |
14 | public class AttributeMetadataCollection : ReflectionMetadataCollection |
|
11 | { |
15 | { |
|
12 | private static readonly Dictionary<Type, List<SearchableMetadata>> _propertiesCache = |
16 | private static readonly Dictionary<Type, List<SearchableMetadata>> PropertiesCache = |
|
Line 13... | Line 17... | |||
13 | new Dictionary<Type, List<SearchableMetadata>>(); |
17 | new Dictionary<Type, List<SearchableMetadata>>(); |
|
Line 14... | Line 18... | |||
14 | |
18 | |
|
Line 22... | Line 26... | |||
22 | |
26 | |
|
23 | public override IEnumerable<IMetadata> All |
27 | public override IEnumerable<IMetadata> All |
|
24 | { |
28 | { |
|
25 | get |
29 | get |
|
26 | { |
30 | { |
|
27 | if (_propertiesCache.TryGetValue(_targetType, out var storedProperty)) |
31 | if (PropertiesCache.TryGetValue(_targetType, out var storedProperty)) |
|
Line 28... | Line 32... | |||
28 | return storedProperty; |
32 | return storedProperty; |
|
29 | |
- | ||
30 | var searchableProperties = new List<SearchableMetadata>(); |
33 | |
|
31 | |
34 | var searchableProperties = new List<SearchableMetadata>(); |
|
32 | var properties = _targetType.GetProperties(); |
35 | var properties = _targetType.GetProperties(); |
|
33 | foreach (var property in properties) |
- | ||
34 | { |
36 | foreach (var property in properties) |
|
35 | var searchablePropertyAttribute = |
37 | { |
|
36 | property.GetCustomAttribute(typeof(SearchablePropertyAttribute), false) as |
- | ||
37 | SearchablePropertyAttribute; |
- | ||
- | 38 | if (!(property.GetCustomAttribute(typeof(SearchablePropertyAttribute), false) is |
||
38 | if (searchablePropertyAttribute != null) |
39 | SearchablePropertyAttribute searchablePropertyAttribute)) continue; |
|
39 | { |
40 | |
|
40 | var searchableProperty = new SearchableMetadata(property); |
41 | var searchableProperty = new SearchableMetadata(property); |
|
Line 41... | Line 42... | |||
41 | if (!string.IsNullOrWhiteSpace(searchablePropertyAttribute.SearchName)) |
42 | if (!string.IsNullOrWhiteSpace(searchablePropertyAttribute.SearchName)) |
|
Line 42... | Line 43... | |||
42 | searchableProperty.SearchName = searchablePropertyAttribute.SearchName; |
43 | searchableProperty.SearchName = searchablePropertyAttribute.SearchName; |
|
43 | |
- | ||
44 | searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
44 | |
|
Line 45... | Line 45... | |||
45 | |
45 | searchableProperty.Analyze = searchablePropertyAttribute.Analyze; |
|
46 | searchableProperties.Add(searchableProperty); |
46 | |
|
47 | } |
47 | searchableProperties.Add(searchableProperty); |
|
48 | } |
48 | } |
|
49 | |
49 | |
|
50 | _propertiesCache.Add(_targetType, searchableProperties); |
50 | PropertiesCache.Add(_targetType, searchableProperties); |
|
51 | return searchableProperties; |
51 | return searchableProperties; |