You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using the YapDatabaseFullTextSearch extension to index and search all my user data, Contacts and Notes, see below. They are in separate collections, and only Notes has a property to reference its Contact ID. In the main user interface, I have a YapDatabase view and mappings to show all the Contacts. And I have a search controller to search all the Contacts and Notes. I want to dynamically filter only all the contacts view/mappings as the user searches, and only show the contacts for which there are search results in either Contacts or Notes. I do not want to show the Notes, only the Contact that is associated with the Note in the search results.
///// Data modelsstructContact{varid:Stringvarname:String}structNote{varid:StringvarcontactID:String// A contact can have many notesvartext:String}
Currently, in may SearchResultsViewController, I have rigged up a YapDatabaseFilteredView that is updated (by incrementing the versionTag) as the user types a search query, see performSearch below. What is the best way to dynamically filter a view/mappings? Any help or advice will be greatly appreciated. Thank you.
func performSearch(_ query:String){
filteredContacts.removeAll()// A `Set<String>` of all the filtered contact IDs
dbConnection.read{ transaction in
guard let ftsTransaction = transaction.ext("contacts_notes_fts")as?YapDatabaseFullTextSearchTransaction,let filterTransaction = transaction.ext("filteredSearchContacts")as?YapDatabaseFilteredViewTransactionelse{return}letoptions=YapDatabaseFullTextSearchSnippetOptions()
ftsTransaction.enumerateKeysAndObjects(matching: query, with: options){ snippet, collection, key, object, stop in
if let contact = object as?Contact{self.filteredContacts.insert(key)}else if let note = object as?Note{self.filteredContacts.insert(note.contactID)}os_log("filteredContacts.count: %d",self.filteredContacts.count)}}
searchConnection.readWrite{ transaction in
guard let filterTransaction = transaction.ext("filteredSearchContacts")as?YapDatabaseFilteredViewTransactionelse{return}SearchResultsViewController.FilterVersion +=1// You need to update the versionTag or it won't run your filter closure `self.filtering`
filterTransaction.setFiltering(self.filtering, versionTag:String(SearchResultsViewController.FilterVersion))}}
The text was updated successfully, but these errors were encountered:
I'm using the
YapDatabaseFullTextSearch
extension to index and search all my user data, Contacts and Notes, see below. They are in separate collections, and only Notes has a property to reference its Contact ID. In the main user interface, I have a YapDatabase view and mappings to show all the Contacts. And I have a search controller to search all the Contacts and Notes. I want to dynamically filter only all the contacts view/mappings as the user searches, and only show the contacts for which there are search results in either Contacts or Notes. I do not want to show the Notes, only the Contact that is associated with the Note in the search results.Currently, in may SearchResultsViewController, I have rigged up a
YapDatabaseFilteredView
that is updated (by incrementing the versionTag) as the user types a search query, seeperformSearch
below. What is the best way to dynamically filter a view/mappings? Any help or advice will be greatly appreciated. Thank you.The text was updated successfully, but these errors were encountered: