Skip to content

Commit

Permalink
Merge pull request #3029 from Wox-launcher/bao
Browse files Browse the repository at this point in the history
 perfomace improvement for fuzzy match
  • Loading branch information
bao-qian authored May 25, 2020
2 parents 8767813 + bf0154d commit 22ed474
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 275 deletions.
15 changes: 4 additions & 11 deletions Plugins/Wox.Plugin.ControlPanel/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public List<Result> Query(Query query)
foreach (var item in controlPanelItems)
{
var titleMatch = StringMatcher.FuzzySearch(query.Search, item.LocalizedString);
var subTitleMatch = StringMatcher.FuzzySearch(query.Search, item.InfoTip);

item.Score = Math.Max(titleMatch.Score, subTitleMatch.Score);

item.Score = titleMatch.Score;
if (item.Score > 0)
{
var result = new Result
{
Title = item.LocalizedString,
TitleHighlightData = titleMatch.MatchData,
SubTitle = item.InfoTip,
Score = item.Score,
IcoPath = item.IconPath,
Expand All @@ -61,14 +61,7 @@ public List<Result> Query(Query query)
}
};

if (item.Score == titleMatch.Score)
{
result.TitleHighlightData = titleMatch.MatchData;
}
else
{
result.SubTitleHighlightData = subTitleMatch.MatchData;
}


results.Add(result);
}
Expand Down
28 changes: 24 additions & 4 deletions Plugins/Wox.Plugin.Program/Programs/UWP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,39 @@ public Result Result(string query, IPublicAPI api)
Description.Substring(0, DisplayName.Length) == DisplayName)
{
title = Description;
result.Title = title;
var match = StringMatcher.FuzzySearch(query, title);
result.Score = match.Score;
result.TitleHighlightData = match.MatchData;
}
else if (!string.IsNullOrEmpty(Description))
{
title = $"{DisplayName}: {Description}";
var match1 = StringMatcher.FuzzySearch(query, DisplayName);
var match2 = StringMatcher.FuzzySearch(query, title);
if (match1.Score > match2.Score)
{
result.Score = match1.Score;
result.TitleHighlightData = match1.MatchData;
}
else
{
result.Score = match2.Score;
result.TitleHighlightData = match2.MatchData;
}
result.Title = title;

}
else
{
title = DisplayName;
result.Title = title;
var match = StringMatcher.FuzzySearch(query, title);
result.Score = match.Score;
result.TitleHighlightData = match.MatchData;
}
var match = StringMatcher.FuzzySearch(query, title);
result.Title = title;
result.Score = match.Score;
result.TitleHighlightData = match.MatchData;



return result;
}
Expand Down
19 changes: 2 additions & 17 deletions Plugins/Wox.Plugin.Program/Programs/Win32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class Win32 : IProgram
public string FullPath { get; set; }
public string ParentDirectory { get; set; }
public string ExecutableName { get; set; }
public string Description { get; set; }
public bool Valid { get; set; }
public bool Enabled { get; set; }
public string Location => ParentDirectory;
Expand Down Expand Up @@ -55,21 +54,8 @@ public Result Result(string query, IPublicAPI api)
}
};

string title;
if (Description.Length >= Name.Length && Description.Substring(0, Name.Length) == Name)
{
title = Description;
}
else if (!string.IsNullOrEmpty(Description))
{
title = $"{Name}: {Description}";
}
else
{
title = Name;
}
var match = StringMatcher.FuzzySearch(query, title);
result.Title = title;
var match = StringMatcher.FuzzySearch(query, Name);
result.Title = Name;
result.Score = match.Score;
result.TitleHighlightData = match.MatchData;

Expand Down Expand Up @@ -144,7 +130,6 @@ private static Win32 Win32Program(string path)
IcoPath = path,
FullPath = path,
ParentDirectory = Directory.GetParent(path).FullName,
Description = string.Empty,
Valid = true,
Enabled = true
};
Expand Down
Binary file removed Plugins/Wox.Plugin.Sys/Images/checkupdate.png
Binary file not shown.
Binary file added Plugins/Wox.Plugin.Sys/Images/update.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 9 additions & 14 deletions Plugins/Wox.Plugin.Sys/Main.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NLog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand All @@ -6,6 +7,7 @@
using System.Windows.Forms;
using System.Windows.Interop;
using Wox.Infrastructure;
using Wox.Infrastructure.Logger;
using Application = System.Windows.Application;
using Control = System.Windows.Controls.Control;
using FormsApplication = System.Windows.Forms.Application;
Expand Down Expand Up @@ -44,6 +46,8 @@ private enum HRESULT : uint

#endregion

private static readonly NLog.Logger Logger = LogManager.GetCurrentClassLogger();

public Control CreateSettingPanel()
{
var results = Commands();
Expand All @@ -57,20 +61,10 @@ public List<Result> Query(Query query)
foreach (var c in commands)
{
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)
if (titleMatch.Score > 0)
{
c.Score = score;
if (score == titleMatch.Score)
{
c.TitleHighlightData = titleMatch.MatchData;
}
else
{
c.SubTitleHighlightData = subTitleMatch.MatchData;
}
c.Score = titleMatch.Score;
c.TitleHighlightData = titleMatch.MatchData;
results.Add(c);
}
}
Expand Down Expand Up @@ -237,9 +231,10 @@ private List<Result> Commands()
},
new Result
{
PluginDirectory = context.CurrentPluginMetadata.PluginDirectory,
Title = "Check For Update",
SubTitle = "Check for new Wox update",
IcoPath = "Images\\checkupdate.png",
IcoPath = "Images\\update.png",
Action = c =>
{
Application.Current.MainWindow.Hide();
Expand Down
16 changes: 7 additions & 9 deletions Plugins/Wox.Plugin.Sys/Wox.Plugin.Sys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="Images\checkupdate.png">
<None Include="Images\recyclebin.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Images\recyclebin.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Images\shutdown.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Images\sleep.png">
<None Include="Images\sleep.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</None>
<None Include="Images\update.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="Languages\en.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down Expand Up @@ -144,9 +144,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="Images\Images\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<PackageReference Include="JetBrains.Annotations">
<Version>10.3.0</Version>
Expand Down
7 changes: 7 additions & 0 deletions Wox.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ public static void UpdatePluginMetadata(List<Result> results, PluginMetadata met
r.PluginID = metadata.ID;
r.OriginQuery = query;

string key = "EmbededIcon:";
// todo, use icon path type enum in the future
if (!string.IsNullOrEmpty(r.PluginDirectory) && !string.IsNullOrEmpty(r.IcoPath) && !Path.IsPathRooted(r.IcoPath) && !r.IcoPath.StartsWith(key))
{
r.IcoPath = Path.Combine(r.PluginDirectory, r.IcoPath);
}

// ActionKeywordAssigned is used for constructing MainViewModel's query text auto-complete suggestions
// Plugins may have multi-actionkeywords eg. WebSearches. In this scenario it needs to be overriden on the plugin level
if (metadata.ActionKeywords.Count == 1)
Expand Down
25 changes: 0 additions & 25 deletions Wox.Infrastructure/FuzzyMatcher.cs

This file was deleted.

Loading

0 comments on commit 22ed474

Please sign in to comment.