Skip to content
Snippets Groups Projects
Commit 0736f05e authored by lazarog98's avatar lazarog98
Browse files

Initial body search query w/ separated terms

parent 6a65c458
No related branches found
No related tags found
1 merge request!27Resolve "Improve searching"
......@@ -267,18 +267,50 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
}
}
/**
Function to be used to find mails that contain the search terms. All terms (separated by spaces) need to be contained in the search text.
- parameters:
- content: The String that will be searched
- searchText: Search terms (space-separated) that will be searched for
*/
private func containsSearchTerms ( content : String?, searchText: String) -> Bool
{
if searchText == ""
{
return true ///Case empty search
}
if content == nil
{
return false ///Case Mail has no body/subject
}
//var terms = searchText.characters.split(separator: " ")
let terms = searchText.lowercased().components(separatedBy : " ")
var found = true
for t in terms
{
found = found && content!.lowercased().contains(t)
}
return found
}
/**
Filters emails by a user input string and scope
- parameters:
-scope: 0 =
*/
private func _filterContentForSearchText(_ searchText: String, scope: Int = 0) {
var records = [KeyRecord]()
if scope == 0 || scope == 3 {
records += folder.records.filter({ (record: KeyRecord) -> Bool in
return record.name.lowercased().contains(searchText.lowercased())
return containsSearchTerms(content: record.name, searchText: searchText)
})
}
if scope == 1 || scope == 3 {
records += folder.records.filter({ (record: KeyRecord) -> Bool in
let mails = record.inboxMails
return mails.filter({ (mail: PersistentMail) -> Bool in
mail.subject?.lowercased().contains(searchText.lowercased()) ?? false
containsSearchTerms(content: mail.subject, searchText: searchText)
}).count > 0
})
}
......@@ -287,9 +319,9 @@ class InboxViewController: UITableViewController, InboxCellDelegator {
let mails = record.inboxMails
return mails.filter({ (mail: PersistentMail) -> Bool in
if let decryptedBody = mail.decryptedBody {
return decryptedBody.lowercased().contains(searchText.lowercased())
return containsSearchTerms(content: decryptedBody, searchText: searchText)
} else if !mail.isEncrypted {
return mail.body?.lowercased().contains(searchText.lowercased()) ?? false
return containsSearchTerms(content: mail.body, searchText: searchText)
}
return false
}).count > 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment