Update SearchScore and use AsParallel
This commit is contained in:
@ -187,22 +187,25 @@ namespace Elwig.Helpers {
|
|||||||
if (!searchKeywords.Any())
|
if (!searchKeywords.Any())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
words = words.Select(w => w?.ToLower());
|
return words
|
||||||
int i = 0;
|
.Select(w => {
|
||||||
foreach (string? c in words) {
|
w = w?.ToLower();
|
||||||
if (c == null) continue;
|
var p = w?.ToLower()?.Split(" ");
|
||||||
var parts = c.Split(" ");
|
if (w == null || p == null) {
|
||||||
if (searchKeywords.Any(f => c == f)) {
|
return 0;
|
||||||
i += 100;
|
} else if (searchKeywords.Any(f => w == f)) {
|
||||||
} else if (searchKeywords.Any(f => parts.Any(a => a == f))) {
|
return 100;
|
||||||
i += 90;
|
} else if (searchKeywords.Any(f => p.Any(a => a == f))) {
|
||||||
} else if (searchKeywords.Any(f => parts.Any(a => a.StartsWith(f)))) {
|
return 90;
|
||||||
i += 50;
|
} else if (searchKeywords.Any(f => p.Any(a => a.StartsWith(f)))) {
|
||||||
} else if (searchKeywords.Any(f => f != null && c.Contains(f))) {
|
return 50;
|
||||||
i += 1;
|
} else if (searchKeywords.Any(f => f != null && w.Contains(f))) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
return i;
|
.Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (int, string?)? ShowManualWeighingDialog() {
|
public static (int, string?)? ShowManualWeighingDialog() {
|
||||||
|
@ -266,6 +266,8 @@ namespace Elwig.Windows {
|
|||||||
filter.RemoveAt(i--);
|
filter.RemoveAt(i--);
|
||||||
} else if (e.Length > 2 && e.StartsWith("\"") && e.EndsWith("\"")) {
|
} else if (e.Length > 2 && e.StartsWith("\"") && e.EndsWith("\"")) {
|
||||||
filter[i] = e[1..^1];
|
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();
|
List<Delivery> deliveries = await deliveryQuery.OrderByDescending(d => d.DateString).ThenByDescending(d => d.TimeString).ToListAsync();
|
||||||
if (filter.Count > 0 && deliveries.Count > 0) {
|
if (filter.Count > 0 && deliveries.Count > 0) {
|
||||||
var dict = deliveries
|
var dict = deliveries.AsParallel()
|
||||||
.ToDictionary(d => d, d => d.SearchScore(TextFilter))
|
.ToDictionary(d => d, d => d.SearchScore(TextFilter))
|
||||||
.OrderByDescending(a => a.Value)
|
.OrderByDescending(a => a.Value)
|
||||||
.ThenBy(a => a.Key.DateTime);
|
.ThenBy(a => a.Key.DateTime);
|
||||||
|
@ -72,7 +72,7 @@ namespace Elwig.Windows {
|
|||||||
List<Member> members = await memberQuery.ToListAsync();
|
List<Member> members = await memberQuery.ToListAsync();
|
||||||
|
|
||||||
if (TextFilter.Count > 0) {
|
if (TextFilter.Count > 0) {
|
||||||
var dict = members
|
var dict = members.AsParallel()
|
||||||
.ToDictionary(m => m, m => m.SearchScore(TextFilter))
|
.ToDictionary(m => m, m => m.SearchScore(TextFilter))
|
||||||
.OrderByDescending(a => a.Value)
|
.OrderByDescending(a => a.Value)
|
||||||
.ThenBy(a => a.Key.FamilyName)
|
.ThenBy(a => a.Key.FamilyName)
|
||||||
|
Reference in New Issue
Block a user