Update SearchScore and use AsParallel
This commit is contained in:
@ -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 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;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
})
|
||||
.Sum();
|
||||
}
|
||||
|
||||
public static (int, string?)? ShowManualWeighingDialog() {
|
||||
|
@ -266,6 +266,8 @@ namespace Elwig.Windows {
|
||||
filter.RemoveAt(i--);
|
||||
} else if (e.Length > 2 && e.StartsWith("\"") && e.EndsWith("\"")) {
|
||||
filter[i] = e[1..^1];
|
||||
} else if (e.Length <= 2) {
|
||||
filter.RemoveAt(i--);
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,7 +288,7 @@ namespace Elwig.Windows {
|
||||
|
||||
List<Delivery> deliveries = await deliveryQuery.OrderByDescending(d => d.DateString).ThenByDescending(d => d.TimeString).ToListAsync();
|
||||
if (filter.Count > 0 && deliveries.Count > 0) {
|
||||
var dict = deliveries
|
||||
var dict = deliveries.AsParallel()
|
||||
.ToDictionary(d => d, d => d.SearchScore(TextFilter))
|
||||
.OrderByDescending(a => a.Value)
|
||||
.ThenBy(a => a.Key.DateTime);
|
||||
|
@ -72,7 +72,7 @@ namespace Elwig.Windows {
|
||||
List<Member> members = await memberQuery.ToListAsync();
|
||||
|
||||
if (TextFilter.Count > 0) {
|
||||
var dict = members
|
||||
var dict = members.AsParallel()
|
||||
.ToDictionary(m => m, m => m.SearchScore(TextFilter))
|
||||
.OrderByDescending(a => a.Value)
|
||||
.ThenBy(a => a.Key.FamilyName)
|
||||
|
Reference in New Issue
Block a user