Update SearchScore and use AsParallel

This commit is contained in:
2023-08-26 19:39:28 +02:00
parent ba71618463
commit c0a6f16374
3 changed files with 23 additions and 18 deletions

View File

@ -187,22 +187,25 @@ namespace Elwig.Helpers {
if (!searchKeywords.Any())
return 0;
words = words.Select(w => w?.ToLower());
int i = 0;
foreach (string? c in words) {
if (c == null) continue;
var parts = c.Split(" ");
if (searchKeywords.Any(f => c == f)) {
i += 100;
} else if (searchKeywords.Any(f => parts.Any(a => a == f))) {
i += 90;
} else if (searchKeywords.Any(f => parts.Any(a => a.StartsWith(f)))) {
i += 50;
} else if (searchKeywords.Any(f => f != null && c.Contains(f))) {
i += 1;
}
}
return i;
return words
.Select(w => {
w = w?.ToLower();
var p = w?.ToLower()?.Split(" ");
if (w == null || p == null) {
return 0;
} else if (searchKeywords.Any(f => w == f)) {
return 100;
} else if (searchKeywords.Any(f => p.Any(a => a == f))) {
return 90;
} else if (searchKeywords.Any(f => p.Any(a => a.StartsWith(f)))) {
return 50;
} else if (searchKeywords.Any(f => f != null && w.Contains(f))) {
return 1;
} else {
return 0;
}
})
.Sum();
}
public static (int, string?)? ShowManualWeighingDialog() {