mirror of https://github.com/oxen-io/session-ios
WIP: FTS - rudimentary show results
-[] Backend -[] indexes e5.25 -[x] wire up results: Contacts / Conversations / Messages actual: 3hr -[ ] group thread est: actual: -[x] group name actual: e.25 -[ ] group member name: e.25 -[ ] group member number: e.25 -[ ] contact thread e.5 -[ ] name -[ ] number -[ ] messages e1 -[ ] content -[] Frontend e10.75 -[x] wire up VC's a.5 -[x] show search results only when search box has content a.25 -[] show search results: Contact / Conversation / Messages e2 -[x] wire up matchs -[] style contact cell -[] style conversation cell -[] style messages cell -[] tapping thread search result takes you to conversation e1 -[] tapping message search result takes you to message e1 -[] show snippet text for matched message e1 -[] highlight matched text in thread e3 -[] go to next search result in thread e2 -[] No Results page -[] Hide search unless pulled downpull/1/head
parent
ffea3a020f
commit
a9e2834d9f
@ -0,0 +1,54 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
@objc
|
||||
public class FullTextSearchFinder: NSObject {
|
||||
|
||||
public func enumerateObjects(searchText: String, transaction: YapDatabaseReadTransaction, block: @escaping (Any) -> Void) {
|
||||
guard let ext = ext(transaction: transaction) else {
|
||||
assertionFailure("ext was unexpectedly nil")
|
||||
return
|
||||
}
|
||||
|
||||
ext.enumerateKeysAndObjects(matching: searchText) { (_, _, object, _) in
|
||||
block(object)
|
||||
}
|
||||
}
|
||||
|
||||
private func ext(transaction: YapDatabaseReadTransaction) -> YapDatabaseFullTextSearchTransaction? {
|
||||
return transaction.ext(FullTextSearchFinder.dbExtensionName) as? YapDatabaseFullTextSearchTransaction
|
||||
}
|
||||
|
||||
// MARK: - Extension Registration
|
||||
|
||||
private static let dbExtensionName: String = "FullTextSearchFinderExtension"
|
||||
|
||||
@objc
|
||||
public class func asyncRegisterDatabaseExtension(storage: OWSStorage) {
|
||||
storage.asyncRegister(dbExtensionConfig, withName: dbExtensionName)
|
||||
}
|
||||
|
||||
// Only for testing.
|
||||
public class func syncRegisterDatabaseExtension(storage: OWSStorage) {
|
||||
storage.register(dbExtensionConfig, withName: dbExtensionName)
|
||||
}
|
||||
|
||||
private class var dbExtensionConfig: YapDatabaseFullTextSearch {
|
||||
let contentColumnName = "content"
|
||||
let handler = YapDatabaseFullTextSearchHandler.withObjectBlock { (dict: NSMutableDictionary, _: String, _: String, object: Any) in
|
||||
if let groupThread = object as? TSGroupThread {
|
||||
dict[contentColumnName] = groupThread.groupModel.groupName
|
||||
}
|
||||
}
|
||||
|
||||
// update search index on contact name changes?
|
||||
// update search index on message insertion?
|
||||
|
||||
// TODO is it worth doing faceted search, i.e. Author / Name / Content?
|
||||
// seems unlikely that mobile users would use the "author: Alice" search syntax.
|
||||
return YapDatabaseFullTextSearch(columnNames: ["content"], handler: handler)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue