2020-08-12 04:40:26 +08:00
|
|
|
|
// 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;
|
|
|
|
|
|
2020-08-13 01:44:58 +08:00
|
|
|
|
[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
2020-08-12 04:40:26 +08:00
|
|
|
|
|
|
|
|
|
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>
|
2020-10-30 08:52:35 +08:00
|
|
|
|
/// Gets matched data to highlight.
|
2020-08-12 04:40:26 +08:00
|
|
|
|
/// </summary>
|
2020-10-30 08:52:35 +08:00
|
|
|
|
public List<int> MatchData { get; private set; }
|
2020-08-12 04:40:26 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|