diff --git a/Flow.Launcher/Storage/UserSelectedRecord.cs b/Flow.Launcher/Storage/UserSelectedRecord.cs index fd3d87fc4..e75ac7f63 100644 --- a/Flow.Launcher/Storage/UserSelectedRecord.cs +++ b/Flow.Launcher/Storage/UserSelectedRecord.cs @@ -1,5 +1,7 @@ using System.Collections.Generic; +using System.Linq; using System.Text.Json.Serialization; +using Flow.Launcher.Infrastructure; using Flow.Launcher.Infrastructure.Storage; using Flow.Launcher.Plugin; @@ -8,16 +10,42 @@ namespace Flow.Launcher.Storage public class UserSelectedRecord { [JsonInclude] - public Dictionary records { get; private set; } + public Dictionary records { get; private set; } public UserSelectedRecord() { - records = new Dictionary(); + records = new Dictionary(); + } + + private static int GenerateCustomHashCode(Query query, Result result) + { + int hashcode = 23; + + unchecked + { + // skip the empty space + foreach (var item in query.ActionKeyword.Concat(query.Search)) + { + hashcode = hashcode * 31 + item; + } + + foreach (var item in result.Title) + { + hashcode = hashcode * 31 + item; + } + + foreach (var item in result.SubTitle) + { + hashcode = hashcode * 31 + item; + } + return hashcode; + + } } public void Add(Result result) { - var key = result.ToString(); + var key = GenerateCustomHashCode(result.OriginQuery, result); if (records.ContainsKey(key)) { records[key]++; @@ -31,7 +59,7 @@ namespace Flow.Launcher.Storage public int GetSelectedCount(Result result) { - if (records.TryGetValue(result.ToString(), out int value)) + if (records.TryGetValue(GenerateCustomHashCode(result.OriginQuery, result), out int value)) { return value; }