Browse Source

Changed way how fitness is calculated, now it's based purely on name length (ignoring generic arguments)

pull/668/head
Ondrej Petrzilka 9 years ago
parent
commit
d6db2c07e8
  1. 48
      ILSpy/SearchStrategies.cs

48
ILSpy/SearchStrategies.cs

@ -30,35 +30,21 @@ namespace ICSharpCode.ILSpy
searchTerm = terms; searchTerm = terms;
} }
protected float GetFitness(string text) protected float CalculateFitness(MemberReference member, string text)
{ {
// TODO: Is it possible to get fitness for regex? // Ignore generic arguments, it not possible to search based on them either
if (regex != null) int length = 0;
return 1; int generics = 0;
for (int i = 0; i < text.Length; i++)
float result = 0; {
for (int i = 0; i < searchTerm.Length; ++i) { if (text[i] == '<')
// How to handle overlapping matches? generics++;
var term = searchTerm[i]; else if (text[i] == '>')
switch (term[0]) generics--;
{ else if (generics == 0)
case '+': // must contain length++;
term = term.Substring(1); }
goto default; return 1.0f / length;
case '-': // should not contain, ignore
break;
case '=': // exact match
term = term.Substring(1);
goto default;
default:
if (text.IndexOf(term, StringComparison.OrdinalIgnoreCase) >= 0)
{
result += term.Length / (float)text.Length;
}
break;
}
}
return result;
} }
protected bool IsMatch(string text) protected bool IsMatch(string text)
@ -125,7 +111,7 @@ namespace ICSharpCode.ILSpy
addResult(new SearchResult addResult(new SearchResult
{ {
Member = item, Member = item,
Fitness = GetFitness(item.Name), Fitness = CalculateFitness(item, item.Name),
Image = image(item), Image = image(item),
Name = item.Name, Name = item.Name,
LocationImage = TypeTreeNode.GetIcon(type), LocationImage = TypeTreeNode.GetIcon(type),
@ -393,7 +379,7 @@ namespace ICSharpCode.ILSpy
string name = language.TypeToString(type, includeNamespace: false); string name = language.TypeToString(type, includeNamespace: false);
addResult(new SearchResult { addResult(new SearchResult {
Member = type, Member = type,
Fitness = GetFitness(name), Fitness = CalculateFitness(type, name),
Image = TypeTreeNode.GetIcon(type), Image = TypeTreeNode.GetIcon(type),
Name = name, Name = name,
LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace, LocationImage = type.DeclaringType != null ? TypeTreeNode.GetIcon(type.DeclaringType) : Images.Namespace,

Loading…
Cancel
Save