mirror of
https://github.com/kiwix/kiwix-apple.git
synced 2025-09-24 04:03:03 -04:00
Search Performance Optimization
This commit is contained in:
parent
8f79ec77dc
commit
0886711f59
@ -54,7 +54,7 @@ extension MainVC: LPTBarButtonItemDelegate, TableOfContentsDelegate, UISearchBar
|
||||
}
|
||||
|
||||
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
|
||||
searchController?.searchText = searchText
|
||||
searchController?.startSearch(searchText, delayed: true)
|
||||
}
|
||||
|
||||
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
|
||||
|
@ -59,11 +59,11 @@ class RecentSearchCVC: UIViewController, UICollectionViewDataSource, UICollectio
|
||||
|
||||
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
|
||||
guard let mainVC = parentViewController?.parentViewController?.parentViewController as? MainVC,
|
||||
let SearchController = parentViewController?.parentViewController as? SearchController,
|
||||
let searchController = parentViewController?.parentViewController as? SearchController,
|
||||
let cell = collectionView.cellForItemAtIndexPath(indexPath) as? LocalLangCell,
|
||||
let text = cell.label.text else {return}
|
||||
mainVC.searchBar.text = text
|
||||
SearchController.searchText = text
|
||||
searchController.startSearch(text, delayed: false)
|
||||
collectionView.deselectItemAtIndexPath(indexPath, animated: true)
|
||||
}
|
||||
|
||||
|
@ -15,10 +15,9 @@ class SearchController: UIViewController, UISearchBarDelegate, UIGestureRecogniz
|
||||
@IBOutlet var tapGestureRecognizer: UITapGestureRecognizer!
|
||||
var searchResultTBVC: SearchResultTBVC?
|
||||
|
||||
var searchText = "" {
|
||||
private var searchText = "" {
|
||||
didSet {
|
||||
configureViewVisibility()
|
||||
searchResultTBVC?.startSearch(searchText)
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +56,22 @@ class SearchController: UIViewController, UISearchBarDelegate, UIGestureRecogniz
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Search
|
||||
|
||||
func startSearch(searchText: String, delayed: Bool) {
|
||||
self.searchText = searchText
|
||||
if delayed {
|
||||
let previousSearchText = searchText
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(275 * USEC_PER_SEC)), dispatch_get_main_queue()) {
|
||||
print("\(previousSearchText), \(self.searchText)")
|
||||
guard previousSearchText == self.searchText else {return}
|
||||
self.searchResultTBVC?.startSearch(self.searchText)
|
||||
}
|
||||
} else {
|
||||
searchResultTBVC?.startSearch(self.searchText)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Handle Gesture
|
||||
|
||||
func handleTap(tapGestureRecognizer: UIGestureRecognizer) {
|
||||
|
@ -36,7 +36,7 @@
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1388</string>
|
||||
<string>1416</string>
|
||||
<key>ITSAppUsesNonExemptEncryption</key>
|
||||
<false/>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
|
@ -38,6 +38,7 @@ class SearchOperation: GroupOperation {
|
||||
}
|
||||
|
||||
override func finished(errors: [NSError]) {
|
||||
print(cancelled)
|
||||
NSOperationQueue.mainQueue().addOperationWithBlock {
|
||||
self.completionHandler(self.results)
|
||||
}
|
||||
|
@ -168,7 +168,13 @@ class SearchResult: CustomStringConvertible {
|
||||
|
||||
let probability: Double? // range: 0.0 - 1.0
|
||||
let distance: Int // Levenshtein distance, non negative integer
|
||||
let score: Double
|
||||
private(set) lazy var score: Double = {
|
||||
if let probability = self.probability {
|
||||
return WeightFactor.calculate(probability) * Double(self.distance)
|
||||
} else {
|
||||
return Double(self.distance)
|
||||
}
|
||||
}()
|
||||
|
||||
init?(rawResult: [String: AnyObject]) {
|
||||
let title = (rawResult["title"] as? String) ?? ""
|
||||
@ -184,7 +190,6 @@ class SearchResult: CustomStringConvertible {
|
||||
return nil
|
||||
}
|
||||
}()
|
||||
let score = WeightFactor.calculate(probability ?? 1) * Double(distance)
|
||||
|
||||
self.title = title
|
||||
self.path = path
|
||||
@ -192,7 +197,6 @@ class SearchResult: CustomStringConvertible {
|
||||
self.snippet = snippet
|
||||
self.probability = probability
|
||||
self.distance = distance
|
||||
self.score = score
|
||||
|
||||
if title == "" || path == "" || bookID == "" {return nil}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user