mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
add score bumping with query and do hashcode customized
This commit is contained in:
parent
b5e54a76b0
commit
362504e223
1 changed files with 32 additions and 4 deletions
|
|
@ -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<string, int> records { get; private set; }
|
||||
public Dictionary<int, int> records { get; private set; }
|
||||
|
||||
public UserSelectedRecord()
|
||||
{
|
||||
records = new Dictionary<string, int>();
|
||||
records = new Dictionary<int, int>();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue