@@ -84,6 +84,8 @@ public SearchClient(SearchConfig config)
8484 /// </summary>
8585 public int Pending { get ; private set ; }
8686
87+ public List < SearchResult > AllResults => Results . Union ( FilteredResults ) . Distinct ( ) . ToList ( ) ;
88+
8789 /// <summary>
8890 /// Reloads <see cref="Config" /> and <see cref="Engines" /> accordingly.
8991 /// </summary>
@@ -190,6 +192,7 @@ public async Task RunSearchAsync()
190192 } ) ;
191193
192194 IsComplete = ! tasks . Any ( ) ;
195+
193196 }
194197
195198 Trace . WriteLine ( $ "{ nameof ( SearchClient ) } : Search complete", C_SUCCESS ) ;
@@ -210,28 +213,7 @@ public async Task RunSearchAsync()
210213 SearchCompleted ? . Invoke ( null , args ) ;
211214 }
212215
213- public async void FindDirectResults ( SearchResult result )
214- {
215- Debug . WriteLine ( $ "searching within { result . Engine . Name } ") ;
216-
217- foreach ( ImageResult ir in result . AllResults ) {
218- var b = await ir . TryScanForDirectImages ( ) ;
219-
220- if ( b && ! DirectResults . Contains ( ir ) ) {
221-
222- Debug . WriteLine ( $ "{ nameof ( SearchClient ) } : Found direct result { ir . Direct . Url } ") ;
223- DirectResults . Add ( ir ) ;
224- result . PrimaryResult . Direct . Url ??= ir . Direct . Url ;
225-
226- DirectFound ? . Invoke ( null , new DirectResultsFoundEventArgs
227- {
228- DirectResultsSubset = new ( ) { ir } ,
229- } ) ;
230-
231- ResultUpdated ? . Invoke ( null , EventArgs . Empty ) ;
232- }
233- }
234- }
216+
235217
236218
237219 private void FindDirectResults ( object state , SearchResult value , int take2 = 5 )
@@ -247,14 +229,21 @@ private void FindDirectResults(object state, SearchResult value, int take2 = 5)
247229 Debug . WriteLine ( $ "*{ nameof ( SearchClient ) } : Found { images . Count } direct results", C_DEBUG ) ;
248230 DirectResults . AddRange ( images ) ;
249231
250- DirectFound ? . Invoke ( null , new DirectResultsFoundEventArgs
251- {
252- DirectResultsSubset = images ,
253- } ) ;
254232 }
255233 else {
256- var t = Task . Factory . StartNew ( ( ) => FindDirectResults ( value ) ) ;
234+ var t = Task . Factory . StartNew ( async ( ) =>
235+ {
236+ if ( value . Scanned ) {
237+ return ;
238+ }
239+ var d = await value . FindDirectResults ( ) ;
240+ Debug . WriteLine ( $ "adding { d . Count } to { DirectResults . Count } ") ;
241+ DirectResults . AddRange ( d ) ;
242+ value . Scanned = true ;
257243
244+ ResultUpdated ? . Invoke ( null , EventArgs . Empty ) ;
245+ } ) ;
246+
258247 }
259248 }
260249
@@ -374,11 +363,7 @@ public static BaseSearchEngine[] GetAllSearchEngines()
374363 /// Fires when a search is complete (<see cref="RunSearchAsync" />).
375364 /// </summary>
376365 public event EventHandler < SearchCompletedEventArgs > SearchCompleted ;
377-
378- /// <summary>
379- /// Fires when a direct image result is found (<see cref="FindDirectResults"/>)
380- /// </summary>
381- public event EventHandler < DirectResultsFoundEventArgs > DirectFound ;
366+
382367
383368 private static readonly Predicate < SearchResult > DetailPredicate = r => r . IsNonPrimitive ;
384369
0 commit comments