mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Take space into consideration while calculating the first matched index (#3874)
This commit is contained in:
parent
bc8a1f6a8f
commit
30c37f06ae
1 changed files with 26 additions and 1 deletions
|
|
@ -83,9 +83,18 @@ namespace Flow.Launcher.Infrastructure
|
||||||
bool allSubstringsContainedInCompareString = true;
|
bool allSubstringsContainedInCompareString = true;
|
||||||
|
|
||||||
var indexList = new List<int>();
|
var indexList = new List<int>();
|
||||||
|
List<int> spaceIndices = new List<int>();
|
||||||
|
|
||||||
for (var compareStringIndex = 0; compareStringIndex < fullStringToCompareWithoutCase.Length; compareStringIndex++)
|
for (var compareStringIndex = 0; compareStringIndex < fullStringToCompareWithoutCase.Length; compareStringIndex++)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// To maintain a list of indices which correspond to spaces in the string to compare
|
||||||
|
// To populate the list only for the first query substring
|
||||||
|
if (fullStringToCompareWithoutCase[compareStringIndex].Equals(' ') && currentQuerySubstringIndex == 0)
|
||||||
|
{
|
||||||
|
spaceIndices.Add(compareStringIndex);
|
||||||
|
}
|
||||||
|
|
||||||
if (fullStringToCompareWithoutCase[compareStringIndex] != currentQuerySubstring[currentQuerySubstringCharacterIndex])
|
if (fullStringToCompareWithoutCase[compareStringIndex] != currentQuerySubstring[currentQuerySubstringCharacterIndex])
|
||||||
{
|
{
|
||||||
matchFoundInPreviousLoop = false;
|
matchFoundInPreviousLoop = false;
|
||||||
|
|
@ -147,7 +156,8 @@ namespace Flow.Launcher.Infrastructure
|
||||||
// proceed to calculate score if every char or substring without whitespaces matched
|
// proceed to calculate score if every char or substring without whitespaces matched
|
||||||
if (allQuerySubstringsMatched)
|
if (allQuerySubstringsMatched)
|
||||||
{
|
{
|
||||||
var score = CalculateSearchScore(query, stringToCompare, firstMatchIndex, lastMatchIndex - firstMatchIndex, allSubstringsContainedInCompareString);
|
var nearestSpaceIndex = CalculateClosestSpaceIndex(spaceIndices, firstMatchIndex);
|
||||||
|
var score = CalculateSearchScore(query, stringToCompare, firstMatchIndex - nearestSpaceIndex - 1, lastMatchIndex - firstMatchIndex, allSubstringsContainedInCompareString);
|
||||||
|
|
||||||
return new MatchResult(true, UserSettingSearchPrecision, indexList, score);
|
return new MatchResult(true, UserSettingSearchPrecision, indexList, score);
|
||||||
}
|
}
|
||||||
|
|
@ -155,6 +165,21 @@ namespace Flow.Launcher.Infrastructure
|
||||||
return new MatchResult (false, UserSettingSearchPrecision);
|
return new MatchResult (false, UserSettingSearchPrecision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To get the index of the closest space which preceeds the first matching index
|
||||||
|
private int CalculateClosestSpaceIndex(List<int> spaceIndices, int firstMatchIndex)
|
||||||
|
{
|
||||||
|
if(spaceIndices.Count == 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int? ind = spaceIndices.OrderBy(item => (firstMatchIndex - item)).Where(item => firstMatchIndex > item).FirstOrDefault();
|
||||||
|
int closestSpaceIndex = ind ?? -1;
|
||||||
|
return closestSpaceIndex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQuerySubstringCharacterIndex,
|
private static bool AllPreviousCharsMatched(int startIndexToVerify, int currentQuerySubstringCharacterIndex,
|
||||||
string fullStringToCompareWithoutCase, string currentQuerySubstring)
|
string fullStringToCompareWithoutCase, string currentQuerySubstring)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue