mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 03:36:44 +02:00
Allow searches in context menu
This commit is contained in:
33
Wox.Infrastructure/StringMatcher.cs
Normal file
33
Wox.Infrastructure/StringMatcher.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Infrastructure
|
||||
{
|
||||
public class StringMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// Check if a candidate is match with the source
|
||||
/// </summary>
|
||||
/// <param name="source"></param>
|
||||
/// <param name="candidate"></param>
|
||||
/// <returns>Match score</returns>
|
||||
public static int Match(string source, string candidate)
|
||||
{
|
||||
if (string.IsNullOrEmpty(source) || string.IsNullOrEmpty(candidate)) return 0;
|
||||
|
||||
FuzzyMatcher matcher = FuzzyMatcher.Create(candidate);
|
||||
int score = matcher.Evaluate(source).Score;
|
||||
if (score > 0) return score;
|
||||
|
||||
score = matcher.Evaluate(source.Unidecode()).Score;
|
||||
return score;
|
||||
}
|
||||
|
||||
public static bool IsMatch(string source, string candidate)
|
||||
{
|
||||
return Match(source, candidate) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,6 +66,7 @@
|
||||
<Compile Include="Storage\BinaryStorage.cs" />
|
||||
<Compile Include="Storage\IStorage.cs" />
|
||||
<Compile Include="Storage\JsonStorage.cs" />
|
||||
<Compile Include="StringMatcher.cs" />
|
||||
<Compile Include="Timeit.cs" />
|
||||
<Compile Include="Unidecoder.Characters.cs" />
|
||||
<Compile Include="Http\HttpRequest.cs" />
|
||||
|
||||
Reference in New Issue
Block a user