@@ -31,6 +31,13 @@ public protocol ContactFetchable {
31
31
func frozenContactsAsync( matching string: String , fetchLimit: Int ? , sorted: ( ( MergedContact , MergedContact ) -> Bool ) ? ) async
32
32
-> any Collection < MergedContact >
33
33
34
+ /// Case and diacritic insensitive search for a `GroupContact`
35
+ /// - Parameters:
36
+ /// - string: input string to match against email and name
37
+ /// - fetchLimit: limit the query by default to limit memory footprint
38
+ /// - Returns: The collection of matching contacts.
39
+ func frozenGroupContacts( matching string: String , fetchLimit: Int ? ) -> any Collection < GroupContact >
40
+
34
41
/// Get a contact from a given transactionable
35
42
func getContact( for correspondent: any Correspondent , transactionable: Transactionable ) -> MergedContact ?
36
43
@@ -43,6 +50,7 @@ public protocol ContactFetchable {
43
50
public extension ContactManager {
44
51
/// Both *case* insensitive __and__ *diacritic* (accents) insensitive
45
52
static let searchContactInsensitivePredicate = " name contains[cd] %@ OR email contains[cd] %@ "
53
+ static let searchGroupContactInsensitivePredicate = " name contains[cd] %@ "
46
54
47
55
/// Making sure, that by default, we do not overflow memory with too much contacts
48
56
private static let contactFetchLimit = 120
@@ -76,6 +84,25 @@ public extension ContactManager {
76
84
return frozenContacts ( matching: string, fetchLimit: fetchLimit, sorted: sorted)
77
85
}
78
86
87
+ /// Case and diacritic insensitive search for a `GroupContact`
88
+ /// - Parameters:
89
+ /// - string: input string to match against email and name
90
+ /// - fetchLimit: limit the query by default to limit memory footprint
91
+ /// - Returns: The collection of matching contacts. Frozen.
92
+ func frozenGroupContacts( matching string: String , fetchLimit: Int ? ) -> any Collection < GroupContact > {
93
+ var lazyResults = fetchResults ( ofType: GroupContact . self) { partial in
94
+ partial
95
+ }
96
+ lazyResults = lazyResults
97
+ . filter ( Self . searchGroupContactInsensitivePredicate, string, string)
98
+ . freeze ( )
99
+
100
+ let fetchLimit = min ( lazyResults. count, fetchLimit ?? Self . contactFetchLimit)
101
+
102
+ let limitedResults = lazyResults [ 0 ..< fetchLimit]
103
+ return limitedResults
104
+ }
105
+
79
106
func getContact( for correspondent: any Correspondent ) -> MergedContact ? {
80
107
getContact ( for: correspondent, transactionable: self )
81
108
}
0 commit comments