@@ -18,7 +18,6 @@ public class IndexDocument<TIndexItem> : IIndexDocument<TIndexItem>
1818 where TIndexItem : IIndexItem
1919 {
2020 private readonly Dictionary < PropertyInfo , IIndexReverse < TIndexItem > > _dict = [ ] ;
21- private readonly List < IndexFieldData > _fields = [ ] ;
2221
2322 /// <summary>
2423 /// Event that is triggered when the schema has changed.
@@ -41,9 +40,9 @@ public class IndexDocument<TIndexItem> : IIndexDocument<TIndexItem>
4140 public IndexType IndexType { get ; private set ; }
4241
4342 /// <summary>
44- /// Return the index field names .
43+ /// Return the index field data .
4544 /// </summary>
46- public IEnumerable < IndexFieldData > Fields => _fields ;
45+ public IEnumerable < IndexFieldData > Fields => Schema . Fields ;
4746
4847 /// <summary>
4948 /// Returns the index context.
@@ -124,11 +123,9 @@ protected virtual void ReBuild(uint capacity)
124123 }
125124 }
126125
127- _fields . Clear ( ) ;
128- _fields . AddRange ( GetFieldData ( typeof ( TIndexItem ) ) ) ;
129126 _dict . Clear ( ) ;
130127
131- foreach ( var field in _fields )
128+ foreach ( var field in Schema . Fields )
132129 {
133130 Add ( field ) ;
134131 }
@@ -183,8 +180,7 @@ protected virtual async Task ReBuildAsync(uint capacity)
183180 }
184181 }
185182
186- var properties = GetFieldData ( typeof ( TIndexItem ) ) ;
187- var tasks = properties . Select ( property => Task . Run ( ( ) => Add ( property ) ) ) ;
183+ var tasks = Schema . Fields . Select ( property => Task . Run ( ( ) => Add ( property ) ) ) ;
188184
189185 await Task . WhenAll ( tasks ) ;
190186 }
@@ -580,44 +576,5 @@ private static bool IsNumericType(PropertyInfo property)
580576 type == typeof ( float ) || type == typeof ( double ) ||
581577 type == typeof ( decimal ) ;
582578 }
583-
584- /// <summary>
585- /// Recursively retrieves the field names of the specified type.
586- /// </summary>
587- /// <param name="type">The type whose field names to retrieve.</param>
588- /// <param name="prefix">The prefix to prepend to each field name.</param>
589- /// <param name="processedTypes">A set of types that have already been processed to avoid circular references.</param>
590- /// <returns>An enumerable collection of field names.</returns>
591- private static IEnumerable < IndexFieldData > GetFieldData ( Type type , string prefix = "" , HashSet < Type > processedTypes = null )
592- {
593- processedTypes ??= [ ] ;
594-
595- if ( processedTypes . Contains ( type ) )
596- {
597- yield break ;
598- }
599-
600- processedTypes . Add ( type ) ;
601-
602- foreach ( var property in type . GetProperties ( ) )
603- {
604- string propertyName = string . IsNullOrEmpty ( prefix ) ? property . Name : $ "{ prefix } .{ property . Name } ";
605-
606- yield return new IndexFieldData
607- {
608- Name = propertyName ,
609- Type = property . PropertyType ,
610- PropertyInfo = property
611- } ;
612-
613- if ( property . PropertyType . IsClass && property . PropertyType != typeof ( string ) )
614- {
615- foreach ( var subProperty in GetFieldData ( property . PropertyType , propertyName , processedTypes ) )
616- {
617- yield return subProperty ;
618- }
619- }
620- }
621- }
622579 }
623580}
0 commit comments