Highlight how results matched

This commit is contained in:
SysC0mp 2019-12-03 15:25:19 +01:00
parent a004ef65af
commit 601d6f37af
7 changed files with 52 additions and 37 deletions

View File

@ -27,7 +27,6 @@ namespace Wox.Plugin.ControlPanel
Directory.CreateDirectory(iconFolder);
}
foreach (ControlPanelItem item in controlPanelItems)
{
if (!File.Exists(iconFolder + item.GUID + fileType) && item.Icon != null)
@ -43,7 +42,10 @@ namespace Wox.Plugin.ControlPanel
foreach (var item in controlPanelItems)
{
item.Score = Score(item, query.Search);
var titleMatch = StringMatcher.FuzzySearch(query.Search, item.LocalizedString);
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, item.InfoTip);
item.Score = Math.Max(titleMatch.Score, subTitleMatch.Score);
if (item.Score > 0)
{
var result = new Result
@ -66,6 +68,16 @@ namespace Wox.Plugin.ControlPanel
return true;
}
};
if (item.Score == titleMatch.Score)
{
result.TitleHighlightData = titleMatch.MatchData;
}
else
{
result.SubTitleHighlightData = subTitleMatch.MatchData;
}
results.Add(result);
}
}
@ -74,26 +86,6 @@ namespace Wox.Plugin.ControlPanel
return panelItems;
}
private int Score(ControlPanelItem item, string query)
{
var scores = new List<int> {0};
if (!string.IsNullOrEmpty(item.LocalizedString))
{
var score1 = StringMatcher.FuzzySearch(query, item.LocalizedString).ScoreAfterSearchPrecisionFilter();
var score2 = StringMatcher.ScoreForPinyin(item.LocalizedString, query);
scores.Add(score1);
scores.Add(score2);
}
if (!string.IsNullOrEmpty(item.InfoTip))
{
var score1 = StringMatcher.FuzzySearch(query, item.InfoTip).ScoreAfterSearchPrecisionFilter();
var score2 = StringMatcher.ScoreForPinyin(item.InfoTip, query);
scores.Add(score1);
scores.Add(score2);
}
return scores.Max();
}
public string GetTranslatedPluginTitle()
{
return context.API.GetTranslation("wox_plugin_controlpanel_plugin_name");

View File

@ -55,6 +55,7 @@ namespace Wox.Plugin.Everything
r.Title = Path.GetFileName(path);
r.SubTitle = path;
r.IcoPath = path;
r.TitleHighlightData = StringMatcher.FuzzySearch(keyword, Path.GetFileName(path)).MatchData;
r.Action = c =>
{
bool hide;
@ -78,6 +79,7 @@ namespace Wox.Plugin.Everything
return hide;
};
r.ContextData = s;
r.SubTitleHighlightData = StringMatcher.FuzzySearch(keyword, path).MatchData;
results.Add(r);
}
}

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
namespace Wox.Plugin.Folder
@ -53,6 +54,7 @@ namespace Wox.Plugin.Folder
Title = item.Nickname,
IcoPath = item.Path,
SubTitle = "Ctrl + Enter to open the directory",
TitleHighlightData = StringMatcher.FuzzySearch(item.Nickname, search).MatchData,
Action = c =>
{
if (c.SpecialKeyState.CtrlPressed)
@ -148,6 +150,8 @@ namespace Wox.Plugin.Folder
}
});
string searchNickname = new FolderLink { Path = query.Search }.Nickname;
//Add children directories
DirectoryInfo[] dirs = new DirectoryInfo(search).GetDirectories();
foreach (DirectoryInfo dir in dirs)
@ -162,6 +166,7 @@ namespace Wox.Plugin.Folder
Title = dir.Name,
IcoPath = dir.FullName,
SubTitle = "Ctrl + Enter to open the directory",
TitleHighlightData = StringMatcher.FuzzySearch(dir.Name, searchNickname).MatchData,
Action = c =>
{
if (c.SpecialKeyState.CtrlPressed)
@ -197,6 +202,7 @@ namespace Wox.Plugin.Folder
{
Title = Path.GetFileName(filePath),
IcoPath = filePath,
TitleHighlightData = StringMatcher.FuzzySearch(file.Name, searchNickname).MatchData,
Action = c =>
{
try

View File

@ -8,6 +8,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Newtonsoft.Json;
using Wox.Infrastructure;
using Wox.Infrastructure.Http;
using Wox.Infrastructure.Logger;
@ -142,6 +143,8 @@ namespace Wox.Plugin.PluginManagement
Title = r.name,
SubTitle = r.description,
IcoPath = "Images\\plugin.png",
TitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, r.name).MatchData,
SubTitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, r.description).MatchData,
Action = c =>
{
MessageBoxResult result = MessageBox.Show("Are you sure you wish to install the \'" + r.name + "\' plugin",
@ -191,6 +194,8 @@ namespace Wox.Plugin.PluginManagement
Title = plugin.Name,
SubTitle = plugin.Description,
IcoPath = plugin.IcoPath,
TitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, plugin.Name).MatchData,
SubTitleHighlightData = StringMatcher.FuzzySearch(query.SecondSearch, plugin.Description).MatchData,
Action = e =>
{
UnInstallPlugin(plugin);

View File

@ -35,7 +35,6 @@ namespace Wox.Plugin.Program.Programs
public UWP(Package package)
{
Location = package.InstalledLocation.Path;
Name = package.Id.Name;
FullName = package.Id.FullName;
@ -266,11 +265,9 @@ namespace Wox.Plugin.Program.Programs
private int Score(string query)
{
var score1 = StringMatcher.FuzzySearch(query, DisplayName).ScoreAfterSearchPrecisionFilter();
var score2 = StringMatcher.ScoreForPinyin(DisplayName, query);
var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
var score4 = StringMatcher.ScoreForPinyin(Description, query);
var score = new[] { score1, score2, score3, score4 }.Max();
var displayNameMatch = StringMatcher.FuzzySearch(query, DisplayName);
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
var score = new[] { displayNameMatch.Score, descriptionMatch.Score }.Max();
return score;
}
@ -293,14 +290,17 @@ namespace Wox.Plugin.Program.Programs
Description.Substring(0, DisplayName.Length) == DisplayName)
{
result.Title = Description;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
}
else if (!string.IsNullOrEmpty(Description))
{
result.Title = $"{DisplayName}: {Description}";
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
}
else
{
result.Title = DisplayName;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, DisplayName).MatchData;
}
return result;
}

View File

@ -33,12 +33,10 @@ namespace Wox.Plugin.Program.Programs
private int Score(string query)
{
var score1 = StringMatcher.FuzzySearch(query, Name).ScoreAfterSearchPrecisionFilter();
var score2 = StringMatcher.ScoreForPinyin(Name, query);
var score3 = StringMatcher.FuzzySearch(query, Description).ScoreAfterSearchPrecisionFilter();
var score4 = StringMatcher.ScoreForPinyin(Description, query);
var score5 = StringMatcher.FuzzySearch(query, ExecutableName).ScoreAfterSearchPrecisionFilter();
var score = new[] { score1, score2, score3, score4, score5 }.Max();
var nameMatch = StringMatcher.FuzzySearch(query, Name);
var descriptionMatch = StringMatcher.FuzzySearch(query, Description);
var executableNameMatch = StringMatcher.FuzzySearch(query, ExecutableName);
var score = new[] { nameMatch.Score, descriptionMatch.Score, executableNameMatch.Score }.Max();
return score;
}
@ -67,14 +65,17 @@ namespace Wox.Plugin.Program.Programs
Description.Substring(0, Name.Length) == Name)
{
result.Title = Description;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
}
else if (!string.IsNullOrEmpty(Description))
{
result.Title = $"{Name}: {Description}";
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Description).MatchData;
}
else
{
result.Title = Name;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
}
return result;

View File

@ -56,12 +56,21 @@ namespace Wox.Plugin.Sys
var results = new List<Result>();
foreach (var c in commands)
{
var titleScore = StringMatcher.FuzzySearch(query.Search, c.Title).ScoreAfterSearchPrecisionFilter();
var subTitleScore = StringMatcher.FuzzySearch(query.Search, c.SubTitle).ScoreAfterSearchPrecisionFilter();
var score = Math.Max(titleScore, subTitleScore);
var titleMatch = StringMatcher.FuzzySearch(query.Search, c.Title);
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, c.SubTitle);
var score = Math.Max(titleMatch.Score, subTitleMatch.Score);
if (score > 0)
{
c.Score = score;
if (score == titleMatch.Score)
{
c.TitleHighlightData = titleMatch.MatchData;
}
else
{
c.SubTitleHighlightData = subTitleMatch.MatchData;
}
results.Add(c);
}
}