mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge pull request #398 from Flow-Launcher/scoreBumpWithQuery
add score bumping with query and do hashcode customized
This commit is contained in:
commit
c78e08abaa
1 changed files with 49 additions and 5 deletions
|
|
@ -1,5 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
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;
|
||||
|
||||
|
|
@ -7,17 +10,58 @@ namespace Flow.Launcher.Storage
|
|||
{
|
||||
public class UserSelectedRecord
|
||||
{
|
||||
private const int HASH_MULTIPLIER = 31;
|
||||
private const int HASH_INITIAL = 23;
|
||||
|
||||
[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 = HASH_INITIAL;
|
||||
|
||||
unchecked
|
||||
{
|
||||
// skip the empty space
|
||||
// https://stackoverflow.com/a/5155015 31 prime and is 2^5 - 1 which allows fast
|
||||
// optimization without information lost when int overflow
|
||||
|
||||
for (int i = 0; i < query.ActionKeyword.Length; i++)
|
||||
{
|
||||
char item = query.ActionKeyword[i];
|
||||
hashcode = hashcode * HASH_MULTIPLIER + item;
|
||||
}
|
||||
|
||||
for (int i = 0; i < query.Search.Length; i++)
|
||||
{
|
||||
char item = query.Search[i];
|
||||
hashcode = hashcode * HASH_MULTIPLIER + item;
|
||||
}
|
||||
|
||||
for (int i = 0; i < result.Title.Length; i++)
|
||||
{
|
||||
char item = result.Title[i];
|
||||
hashcode = hashcode * HASH_MULTIPLIER + item;
|
||||
}
|
||||
|
||||
for (int i = 0; i < result.SubTitle.Length; i++)
|
||||
{
|
||||
char item = result.SubTitle[i];
|
||||
hashcode = hashcode * HASH_MULTIPLIER + 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 +75,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