@@ -59,43 +59,47 @@ protected sealed override IReadOnlyList<Package> FindPackages_UnSafe(string quer
5959
6060 foreach ( IManagerSource source in sources )
6161 {
62- Uri SearchUrl = new ( $ "{ source . Url } /Search()?searchTerm=%27{ HttpUtility . UrlEncode ( query ) } %27&targetFramework=%27%27&includePrerelease=false") ;
62+ string sortingPiece = "&$orderby=Published%20desc" ;
63+ if ( source . Url . Host == "www.powershellgallery.com" ) sortingPiece = "" ;
64+ Uri SearchUrl = new ( $ "{ source . Url } /Search()?searchTerm=%27{ HttpUtility . UrlEncode ( query ) } %27&targetFramework=%27%27&includePrerelease=false{ sortingPiece } ") ;
6365 logger . Log ( $ "Begin package search with url={ SearchUrl } on manager { Name } ") ;
66+ Dictionary < string , SearchResult > AlreadyProcessedPackages = [ ] ;
67+
6468
6569 using HttpClient client = new ( CoreData . GenericHttpClientParameters ) ;
6670 client . DefaultRequestHeaders . UserAgent . ParseAdd ( CoreData . UserAgentString ) ;
67- HttpResponseMessage response = client . GetAsync ( SearchUrl ) . GetAwaiter ( ) . GetResult ( ) ;
68-
69- if ( ! response . IsSuccessStatusCode )
70- {
71- logger . Error ( $ "Failed to fetch api at Url={ SearchUrl } with status code { response . StatusCode } ") ;
72- continue ;
73- }
74-
75- string SearchResults = response . Content . ReadAsStringAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
76- MatchCollection matches = Regex . Matches ( SearchResults , "<entry>([\\ s\\ S]*?)<\\ /entry>" ) ;
77-
78- Dictionary < string , SearchResult > AlreadyProcessedPackages = [ ] ;
71+ HttpResponseMessage response = client . GetAsync ( SearchUrl ) . GetAwaiter ( ) . GetResult ( ) ;
7972
80- foreach ( Match match in matches )
81- {
82- if ( ! match . Success )
73+ if ( ! response . IsSuccessStatusCode )
8374 {
75+ logger . Error ( $ "Failed to fetch api at Url={ SearchUrl } with status code { response . StatusCode } ") ;
8476 continue ;
8577 }
8678
87- string id = Regex . Match ( match . Value , "Id='([^<>']+)'" ) . Groups [ 1 ] . Value ;
88- string version = Regex . Match ( match . Value , "Version='([^<>']+)'" ) . Groups [ 1 ] . Value ;
89- var float_version = CoreTools . VersionStringToStruct ( version ) ;
90- // Match title = Regex.Match(match.Value, "<title[ \\\"\\=A-Za-z0-9]+>([^<>]+)<\\/title>");
79+ string SearchResults = response . Content . ReadAsStringAsync ( ) . GetAwaiter ( ) . GetResult ( ) ;
80+ MatchCollection matches = Regex . Matches ( SearchResults , "<entry>([\\ s\\ S]*?)<\\ /entry>" ) ;
9181
92- if ( AlreadyProcessedPackages . TryGetValue ( id , out var value ) && value . version_float >= float_version )
82+ foreach ( Match match in matches )
9383 {
94- continue ;
84+ if ( ! match . Success )
85+ {
86+ continue ;
87+ }
88+
89+ string id = Regex . Match ( match . Value , "Id='([^<>']+)'" ) . Groups [ 1 ] . Value ;
90+ string version = Regex . Match ( match . Value , "Version='([^<>']+)'" ) . Groups [ 1 ] . Value ;
91+ var float_version = CoreTools . VersionStringToStruct ( version ) ;
92+ // Match title = Regex.Match(match.Value, "<title[ \\\"\\=A-Za-z0-9]+>([^<>]+)<\\/title>");
93+
94+ if ( AlreadyProcessedPackages . TryGetValue ( id , out var value ) &&
95+ value . version_float >= float_version )
96+ {
97+ continue ;
98+ }
99+
100+ AlreadyProcessedPackages [ id ] = new SearchResult { id = id , version = version , version_float = float_version } ;
95101 }
96102
97- AlreadyProcessedPackages [ id ] = new SearchResult { id = id , version = version , version_float = float_version } ;
98- }
99103 foreach ( SearchResult package in AlreadyProcessedPackages . Values )
100104 {
101105 logger . Log ( $ "Found package { package . id } version { package . version } on source { source . Name } ") ;
0 commit comments