// 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 matchData, int rawScore) { Success = success; SearchPrecision = searchPrecision; MatchData = matchData; RawScore = rawScore; } public bool Success { get; set; } /// /// Gets the final score of the match result with search precision filters applied. /// public int Score { get; private set; } /// /// The raw calculated search score without any search precision filtering applied. /// private int _rawScore; public int RawScore { get { return _rawScore; } set { _rawScore = value; Score = ScoreAfterSearchPrecisionFilter(_rawScore); } } /// /// Gets matched data to highlight. /// public List 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; } } }