mirror of
				https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
				synced 2025-10-31 02:05:33 +00:00 
			
		
		
		
	Added generic collections of objects
This commit is contained in:
		| @@ -17,8 +17,15 @@ public interface IXMLRoot { | ||||
|     // Key: the key under which the element(s) will be files | ||||
|     // xPath: the (absolute) XPath to the element(s) | ||||
|     // KeyFunc: How to extrect an identifier for the single element in the collection | ||||
|     // LookupsFunc: Function to generate metadata fields for the object, which will then in turn be a possibility to seach and filter without parsing | ||||
|     // Searchable: Will the element be indexed for full-text-search? | ||||
|     public abstract (string Key, string xPath, Func<XElement, string?> KeyFunc, bool Searchable)[]? XPathCollection { get; } | ||||
|     public abstract ( | ||||
|         string Key,  | ||||
|         string xPath, | ||||
|         Func<XElement, string?> KeyFunc,  | ||||
|         // Func<XElement, Dictionary<string, string[]>> LookupsFunc, | ||||
|         bool Searchable | ||||
|     )[]? XPathCollection { get; } | ||||
|  | ||||
|     // Determines child objects to be collected  | ||||
|     // (deprecated see collections above; only used internally) | ||||
|   | ||||
| @@ -61,15 +61,22 @@ public class XMLService : IXMLService { | ||||
|  | ||||
|     public void SetInProduction(XDocument document) { | ||||
|         if (document == null || _Roots == null) return; | ||||
|         var ret = new ConcurrentDictionary<string, ConcurrentDictionary<string, CollectedItem>>(); | ||||
|         Parallel.ForEach(_Roots, (root) => { | ||||
|         int numProcs = Environment.ProcessorCount; | ||||
|         int concurrencyLevel = numProcs * 2; | ||||
|         int startingSize = 2909; | ||||
|         int startingSizeAllCollections = 23; | ||||
|         var ret = new ConcurrentDictionary<string, ConcurrentDictionary<string, CollectedItem>>(concurrencyLevel, startingSizeAllCollections); | ||||
|         // Note Parallelization brings almost nothing to the table (on a laptop) here and below. | ||||
|         // Parallel.ForEach(_Roots, (root) => { | ||||
|         foreach (var root in _Roots) { | ||||
|             if (root.Value.XPathCollection != null) | ||||
|                 foreach (var coll in root.Value.XPathCollection) { | ||||
|                     var elem = document.XPathSelectElements(coll.xPath); | ||||
|                     if (elem != null && elem.Any()) { | ||||
|                         if (!ret.ContainsKey(coll.Key)) | ||||
|                             ret[coll.Key] = new ConcurrentDictionary<string, CollectedItem>(); | ||||
|                         foreach(var e in elem) { | ||||
|                             ret[coll.Key] = new ConcurrentDictionary<string, CollectedItem>(concurrencyLevel, startingSize); | ||||
|                         Parallel.ForEach(elem, (e) => { | ||||
|                         // foreach(var e in elem) { | ||||
|                             var k = coll.KeyFunc(e); | ||||
|                             if (k != null) { | ||||
|                                 var searchtext = coll.Searchable ?  | ||||
| @@ -77,10 +84,12 @@ public class XMLService : IXMLService { | ||||
|                                     null; | ||||
|                                 ret[coll.Key][k] = new CollectedItem(k, e, root.Value, coll.Key, searchtext); | ||||
|                             } | ||||
|                         } | ||||
|                         // } | ||||
|                         }); | ||||
|                     } | ||||
|                 } | ||||
|         });        | ||||
|         } | ||||
|         // });        | ||||
|         _collectedProduction = ret.ToDictionary(x => x.Key, y => y.Value.ToDictionary(z => z.Key, f => f.Value, null), null); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 schnulller
					schnulller