mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
add scoring based on index and small optimization
This commit is contained in:
parent
28c86af6e9
commit
02b321c4a3
2 changed files with 17 additions and 5 deletions
|
|
@ -59,6 +59,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
{
|
||||
EverythingApiDllImport.Everything_GetMajorVersion();
|
||||
var result = EverythingApiDllImport.Everything_GetLastError() != StateCode.IPCError;
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
|
|
@ -67,6 +68,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
}
|
||||
}
|
||||
|
||||
const int ScoreScaleFactor = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Searches the specified key word and reset the everything API afterwards
|
||||
/// </summary>
|
||||
|
|
@ -115,7 +118,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
|
||||
EverythingApiDllImport.Everything_SetSort(option.SortOption);
|
||||
EverythingApiDllImport.Everything_SetMatchPath(option.IsFullPathSearch);
|
||||
|
||||
|
||||
if (option.SortOption == SortOption.RUN_COUNT_DESCENDING)
|
||||
{
|
||||
EverythingApiDllImport.Everything_SetRequestFlags(EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME | EVERYTHING_REQUEST_RUN_COUNT);
|
||||
|
|
@ -132,10 +135,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
if (!EverythingApiDllImport.Everything_QueryW(true))
|
||||
{
|
||||
CheckAndThrowExceptionOnError();
|
||||
|
||||
yield break;
|
||||
}
|
||||
|
||||
for (var idx = 0; idx < EverythingApiDllImport.Everything_GetNumResults(); ++idx)
|
||||
var numResults = EverythingApiDllImport.Everything_GetNumResults();
|
||||
|
||||
for (var idx = 0; idx < numResults; ++idx)
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
|
|
@ -151,7 +157,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :
|
||||
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
|
||||
ResultType.Volume,
|
||||
Score = (int)EverythingApiDllImport.Everything_GetResultRunCount( (uint)idx)
|
||||
Score = (option.SortOption is SortOption.RUN_COUNT_DESCENDING ? (int)EverythingApiDllImport.Everything_GetResultRunCount((uint)idx) : 0) * ScoreScaleFactor,
|
||||
WindowsIndexed = false
|
||||
};
|
||||
|
||||
yield return result;
|
||||
|
|
@ -192,6 +199,7 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
public static async Task IncrementRunCounterAsync(string fileOrFolder)
|
||||
{
|
||||
await _semaphore.WaitAsync(TimeSpan.FromSeconds(1));
|
||||
|
||||
try
|
||||
{
|
||||
_ = EverythingApiDllImport.Everything_IncRunCountFromFileName(fileOrFolder);
|
||||
|
|
|
|||
|
|
@ -29,12 +29,13 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
public class PathEqualityComparator : IEqualityComparer<Result>
|
||||
{
|
||||
private static PathEqualityComparator instance;
|
||||
|
||||
public static PathEqualityComparator Instance => instance ??= new PathEqualityComparator();
|
||||
|
||||
public bool Equals(Result x, Result y)
|
||||
{
|
||||
return x.Title.Equals(y.Title, StringComparison.OrdinalIgnoreCase)
|
||||
&& string.Equals(x.SubTitle, y.SubTitle, StringComparison.OrdinalIgnoreCase);
|
||||
&& string.Equals(x.SubTitle, y.SubTitle, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public int GetHashCode(Result obj)
|
||||
|
|
@ -106,7 +107,10 @@ namespace Flow.Launcher.Plugin.Explorer.Search
|
|||
|
||||
try
|
||||
{
|
||||
await foreach (var search in searchResults.WithCancellation(token).ConfigureAwait(false))
|
||||
await foreach (var search in searchResults.Select((r, i) => r with
|
||||
{
|
||||
Score = -i + 50
|
||||
}).WithCancellation(token).ConfigureAwait(false))
|
||||
results.Add(ResultManager.CreateResult(query, search));
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
|
|
|
|||
Loading…
Reference in a new issue