From 362504e2239cc60e21391fe11633b6633b4ab877 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Thu, 1 Apr 2021 18:02:27 +0800 Subject: [PATCH] add score bumping with query and do hashcode customized --- Flow.Launcher/Storage/UserSelectedRecord.cs | 36 ++++++++++++++++++--- 1 file changed, 32 insertions(+), 4 deletions(-) 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; }