-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathScoring.cs
More file actions
75 lines (72 loc) · 1.63 KB
/
Copy pathScoring.cs
File metadata and controls
75 lines (72 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Linq;
internal static class Scoring
{
public static int GetMatchScore(string name, string fullName, string query)
{
string text = query.Trim();
if (string.IsNullOrEmpty(text))
{
return 0;
}
if (name.Equals(text, StringComparison.OrdinalIgnoreCase))
{
return 100;
}
if (name.StartsWith(text, StringComparison.OrdinalIgnoreCase))
{
return 80;
}
if (name.Contains(text, StringComparison.OrdinalIgnoreCase) || fullName.Contains(text, StringComparison.OrdinalIgnoreCase))
{
return 60;
}
string text2 = new string(name.Where(char.IsUpper).ToArray());
if (text2.Length >= 2 && text2.Contains(text, StringComparison.OrdinalIgnoreCase))
{
return 50;
}
string[] array = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (array.Length > 1)
{
bool flag = true;
string[] array2 = array;
foreach (string value in array2)
{
if (!name.Contains(value, StringComparison.OrdinalIgnoreCase) && !fullName.Contains(value, StringComparison.OrdinalIgnoreCase))
{
flag = false;
break;
}
}
if (flag)
{
return 40;
}
}
if (IsFuzzySubsequence(name, text))
{
return 20;
}
return 0;
}
private static bool IsFuzzySubsequence(string text, string pattern)
{
string text2 = text.ToLowerInvariant();
string text3 = pattern.ToLowerInvariant();
int startIndex = 0;
string text4 = text3;
foreach (char value in text4)
{
int num = text2.IndexOf(value, startIndex);
if (num < 0)
{
return false;
}
startIndex = num + 1;
}
return true;
}
}