Move CountMachesInMember to Member
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
|
||||
namespace Elwig.Models {
|
||||
[Table("member"), PrimaryKey("MgNr")]
|
||||
@ -125,5 +126,32 @@ namespace Elwig.Models {
|
||||
|
||||
[InverseProperty("Member")]
|
||||
public virtual BillingAddress BillingAddress { get; private set; }
|
||||
|
||||
public int SearchScore(IEnumerable<string> keywords) {
|
||||
keywords = keywords.Where(s => s.Length >= 2 || (s.Length > 0 && s.All(c => char.IsDigit(c))));
|
||||
if (!keywords.Any())
|
||||
return 0;
|
||||
|
||||
string?[] check = new string?[] {
|
||||
MgNr.ToString(),
|
||||
FamilyName.ToLower(), MiddleName?.ToLower(), GivenName.ToLower(),
|
||||
BillingAddress?.Name.ToLower(),
|
||||
Comment?.ToLower(),
|
||||
};
|
||||
|
||||
int i = 0;
|
||||
foreach (string? c in check) {
|
||||
if (c == null) {
|
||||
continue;
|
||||
} else if (keywords.Any(f => c == f)) {
|
||||
i += 100;
|
||||
} else if (keywords.Any(f => c.Split(" ").Any(a => a == f))) {
|
||||
i += 99;
|
||||
} else if (keywords.Any(f => f != null && c.Contains(f))) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user