Move CountMachesInMember to Member

This commit is contained in:
2023-03-21 20:35:21 +01:00
parent 456cdaf3e0
commit c521bf5ffa
2 changed files with 33 additions and 24 deletions

View File

@ -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;
}
}
}