1717using System . IO ;
1818using System . Linq ;
1919using System . Media ;
20+ using System . Net ;
2021using System . Threading ;
2122using System . Threading . Tasks ;
23+ using SimpleCore . Net ;
2224using static SimpleCore . Console . CommandLine . NConsoleOption ;
2325
2426// ReSharper disable ConvertIfStatementToReturnStatement
@@ -78,6 +80,7 @@ public sealed class SearchClient
7880 /// </summary>
7981 public NConsoleInterface Interface { get ; }
8082
83+
8184 private SearchClient ( string img )
8285 {
8386 if ( ! Images . IsFileValid ( img ) ) {
@@ -114,6 +117,30 @@ private SearchClient(string img)
114117 }
115118
116119
120+ private static async void RunAnalysis ( FullSearchResult best )
121+ {
122+
123+ var task = Task . Run ( ( ) =>
124+ {
125+ if ( ! best . IsAnalyzed ) {
126+ var d = Images . Similarity ( best . Url , SearchConfig . Config . Image ) ;
127+
128+ if ( d . HasValue )
129+ {
130+ best . Similarity = ( ( float ) d ) ;
131+ }
132+ }
133+
134+ best . IsAnalyzed = true ;
135+
136+
137+
138+ } ) ;
139+
140+ await task ;
141+ }
142+
143+
117144 /// <summary>
118145 /// Starts search and handles results
119146 /// </summary>
@@ -128,7 +155,7 @@ public async void Start()
128155 var result = finished . Result ;
129156
130157 Results . Add ( result ) ;
131- Results . Sort ( FullSearchResult . CompareResults ) ;
158+
132159
133160 // If the engine is priority, open its result in the browser
134161 if ( result . IsPriority ) {
@@ -139,8 +166,23 @@ public async void Start()
139166
140167 Interface . Status = $ "Searching: { inProgress } /{ len } ";
141168
169+ Results . Sort ( FullSearchResult . CompareResults ) ;
170+
142171 // Reload console UI
143172 NConsole . Refresh ( ) ;
173+
174+
175+ /*
176+ *
177+ */
178+
179+ RunAnalysis ( result ) ;
180+
181+ if ( result . ExtendedResults . Any ( ) ) {
182+ foreach ( var resultExtendedResult in result . ExtendedResults ) {
183+ RunAnalysis ( resultExtendedResult ) ;
184+ }
185+ }
144186 }
145187
146188 /*
@@ -173,6 +215,23 @@ public async void Start()
173215 HandleResultOpen ( best ) ;
174216
175217 }
218+
219+ /*
220+ *
221+ */
222+
223+ Debug . WriteLine ( $ "Analyzing") ;
224+
225+
226+ while ( ! Results . All ( r=> r . IsAnalyzed ) ) {
227+
228+ }
229+
230+ Debug . WriteLine ( $ "Analysis complete") ;
231+
232+ Results . Sort ( FullSearchResult . CompareResults ) ;
233+ NConsole . Refresh ( ) ;
234+
176235 }
177236
178237
0 commit comments