mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-21 15:27:55 +08:00
ec8ead8183
* CA1052: Static holder types should be Static or NotInheritable * CA1041: Provide ObsoleteAttribute message * CA1062: Validate arguments of public methods * CA1304: Specify CultureInfo / CA1305: Specify IFormatProvider / CA1307: Specify StringComparison for clarity * CA1802: Use Literals Where Appropriate * CA1820: Test for empty strings using string length * CA1707: Identifiers should not contain underscores * CA1805: Do not initialize unnecessarily. * CA1822: Mark members as static * CA2227: Collection properties should be read only * CA1054: URI parameters should not be strings * CA1031: Do not catch general exception types * CA1060: Move P/Invokes to NativeMethods class * CA1308: Normalize strings to uppercase * CA2000: Dispose objects before losing scope / CA2234: Pass System.Uri objects instead of strings * CA2234: Pass System.Uri objects instead of strings * CA1044: Properties should not be write only * CA1716: Identifiers should not match keywords * CA2007: Do not directly await a Task * CA2007: Do not directly await a Task (Suppressed) * CA5350: Do Not Use Weak Cryptographic Algorithms (Suppressed) * CA1724: Type names should not match namespaces (renamed Settings.cs to PowerToysRunSettings.cs) * CA1033: Interface methods should be callable by child types (Added sealed modifier to class) * CA1724: Type names should not match namespaces (Renamed Plugin.cs to RunPlugin.cs) * CA1724: Type names should not match namespaces (Renamed Http.cs to HttpClient.cs) * CA5364: Do not use deprecated security protocols (Remove unused code) * Enabled FxCopAnalyzer for Wox.Infrastructure * fixed comment * Addressed comments - Changed Ordinal to InvariantCulture - Added comments - Removed unused obsolete code - Removed unused method (CA2007: Do not directly await a Task) * Addressed comments - fixed justification for CA1031 suppression * Addressed comments - Fixed justification for CA1031 suppression in Wox.Core/Wox.Plugin
78 lines
2.2 KiB
C#
78 lines
2.2 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System.Collections.Generic;
|
|
using System.Runtime.CompilerServices;
|
|
using static Wox.Infrastructure.StringMatcher;
|
|
|
|
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
|
|
|
namespace Wox.Infrastructure
|
|
{
|
|
public class MatchResult
|
|
{
|
|
public MatchResult(bool success, SearchPrecisionScore searchPrecision)
|
|
{
|
|
Success = success;
|
|
SearchPrecision = searchPrecision;
|
|
}
|
|
|
|
public MatchResult(bool success, SearchPrecisionScore searchPrecision, List<int> matchData, int rawScore)
|
|
{
|
|
Success = success;
|
|
SearchPrecision = searchPrecision;
|
|
MatchData = matchData;
|
|
RawScore = rawScore;
|
|
}
|
|
|
|
public bool Success { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets the final score of the match result with search precision filters applied.
|
|
/// </summary>
|
|
public int Score { get; private set; }
|
|
|
|
/// <summary>
|
|
/// The raw calculated search score without any search precision filtering applied.
|
|
/// </summary>
|
|
private int _rawScore;
|
|
|
|
public int RawScore
|
|
{
|
|
get
|
|
{
|
|
return _rawScore;
|
|
}
|
|
|
|
set
|
|
{
|
|
_rawScore = value;
|
|
Score = ScoreAfterSearchPrecisionFilter(_rawScore);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets matched data to highlight.
|
|
/// </summary>
|
|
public List<int> MatchData { get; private set; }
|
|
|
|
public SearchPrecisionScore SearchPrecision { get; set; }
|
|
|
|
public bool IsSearchPrecisionScoreMet()
|
|
{
|
|
return IsSearchPrecisionScoreMet(_rawScore);
|
|
}
|
|
|
|
private bool IsSearchPrecisionScoreMet(int rawScore)
|
|
{
|
|
return rawScore >= (int)SearchPrecision;
|
|
}
|
|
|
|
private int ScoreAfterSearchPrecisionFilter(int rawScore)
|
|
{
|
|
return IsSearchPrecisionScoreMet(rawScore) ? rawScore : 0;
|
|
}
|
|
}
|
|
}
|