Skip to content

Commit 7060df2

Browse files
committed
Quick fix for auto PE
1 parent 39f8073 commit 7060df2

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

SmartImage.Lib/SearchClient.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ namespace SmartImage.Lib;
4242
public sealed class SearchClient : IDisposable, ISearchConfigReceiver
4343
{
4444

45-
public SearchConfig Config { get; private set;}
45+
public SearchConfig Config { get; private set; }
4646

4747
public bool IsComplete { get; private set; }
4848

49-
public IEnumerable<BaseSearchEngine> Engines { get; private set;}
49+
public IEnumerable<BaseSearchEngine> Engines { get; private set; }
5050

5151
public bool ConfigApplied { get; private set; }
5252

@@ -120,6 +120,7 @@ public async Task<bool> RunSearchAsync(SearchQuery query, CancellationToken toke
120120
ConfigApplied = true;
121121

122122
}
123+
123124
var tasks = GetSearchTasks(query, token);
124125

125126
var results = await Task.WhenAll(tasks);
@@ -128,13 +129,21 @@ public async Task<bool> RunSearchAsync(SearchQuery query, CancellationToken toke
128129

129130
CompleteSearchAsync();
130131

132+
if (Config.PriorityEngines == SearchEngineOptions.Auto) {
133+
var best = GetBest(results);
134+
s_logger.LogInformation("Best: {Sr}", best);
135+
if (best != null) {
136+
OpenResult(best.Url);
137+
}
138+
}
139+
131140
return true;
132141
}
133142

134143
/// <inheritdoc />
135144
public async ValueTask<bool> ApplyConfigAsync(SearchConfig cfg, CancellationToken ct = default)
136145
{
137-
Config = cfg;
146+
Config = cfg;
138147
Engines = Config.GetSelectedEngines();
139148

140149
s_logger.LogTrace("Loading engines");
@@ -172,6 +181,8 @@ public static SearchResultItem GetBest(IEnumerable<SearchResult> results)
172181
private void CompleteSearchAsync()
173182
{
174183
ResultChannel?.Writer.Complete();
184+
185+
175186
IsRunning = false;
176187
IsComplete = true;
177188
}

0 commit comments

Comments
 (0)