Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Add free-text optimized search to iOS autofill credential selection screen (#1774)

Leendert de Borst5079a867abf6
diff --git a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
index 5d2de9c15..2bca039f3 100644
--- a/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
+++ b/apps/mobile-app/ios/VaultUI/Selection/CredentialProviderView.swift
@@ -269,7 +269,21 @@ public class CredentialProviderViewModel: ObservableObject {
}
func filterCredentials() {
- filteredCredentials = RustItemMatcher.filterCredentials(credentials, searchText: searchText)
+ // Use RustItemMatcher when iOS provides a URL (autofill context)
+ // Use ItemSearchMatcher when user manually types (free-text search)
+ if let serviceUrl = serviceUrl, searchText == serviceUrl {
+ // iOS provided URL - use Rust matcher for domain-aware matching
+ filteredCredentials = RustItemMatcher.filterCredentials(
+ credentials,
+ currentUrl: searchText
+ )
+ } else {
+ // User-typed search - use substring matching across all fields
+ filteredCredentials = ItemSearchMatcher.filterCredentials(
+ credentials,
+ searchText: searchText
+ )
+ }
}
func handleSelection(username: String, password: String) {
diff --git a/apps/mobile-app/ios/VaultUI/Selection/Utils/ItemSearchMatcher.swift b/apps/mobile-app/ios/VaultUI/Selection/Utils/ItemSearchMatcher.swift
new file mode 100644
index 000000000..36343746c
--- /dev/null
+++ b/apps/mobile-app/ios/VaultUI/Selection/Utils/ItemSearchMatcher.swift
@@ -0,0 +1,78 @@
+import Foundation
+import VaultModels
+
+/// Free-text search matcher for items/credentials.
+/// Uses substring matching across all searchable fields.
+///
+/// Matches behavior of:
+/// - React Native: apps/mobile-app/app/(tabs)/items/index.tsx (lines 269-281)
+/// - Browser Extension: apps/browser-extension/src/entrypoints/background/VaultMessageHandler.ts (filterItemsBySearchTerm)
+/// - Blazor Web: apps/server/AliasVault.Client/Main/Components/Widgets/SearchWidget.razor (lines 224-234)
+public class ItemSearchMatcher {
+
+ /// Filter credentials/items for free-text search using substring matching.
+ ///
+ /// Search logic:
+ /// - Splits search text into individual words
+ /// - Every word must appear in at least one searchable field (AND logic)
+ /// - Case-insensitive substring matching
+ /// - Searches: service name, username, email, URLs, notes
+ /// - Supports partial URL matching (e.g., "mysubdomain.ex" matches "mysubdomain.example.com")
+ ///
+ /// - Parameters:
+ /// - credentials: List of credentials to filter
+ /// - searchText: Free-text search query
+ /// - Returns: Filtered list of credentials matching all search words
+ public static func filterCredentials(_ credentials: [AutofillCredential], searchText: String) -> [AutofillCredential] {
+ // Early return for empty search
+ if searchText.isEmpty {
+ return credentials
+ }
+
+ // Normalize and split search text into words
+ let searchLower = searchText.lowercased().trimmingCharacters(in: .whitespaces)
+ let searchWords = searchLower.split(separator: " ").map { String($0) }.filter { !$0.isEmpty }
+
+ if searchWords.isEmpty {
+ return credentials
+ }
+
+ // Filter credentials: every search word must match at least one field
+ return credentials.filter { credential in
+ // Build searchable fields array
+ var searchableFields: [String] = []
+
+ // Add service name
+ if let serviceName = credential.serviceName {
+ searchableFields.append(serviceName.lowercased())
+ }
+
+ // Add username
+ if let username = credential.username, !username.isEmpty {
+ searchableFields.append(username.lowercased())
+ }
+
+ // Add email
+ if let email = credential.email, !email.isEmpty {
+ searchableFields.append(email.lowercased())
+ }
+
+ // Add all URLs (enables partial URL matching)
+ for url in credential.serviceUrls {
+ searchableFields.append(url.lowercased())
+ }
+
+ // Add notes
+ if let notes = credential.notes, !notes.isEmpty {
+ searchableFields.append(notes.lowercased())
+ }
+
+ // Check if every search word appears in at least one field
+ return searchWords.allSatisfy { word in
+ searchableFields.contains { field in
+ field.contains(word)
+ }
+ }
+ }
+ }
+}