我正在研究通過91,000個條目搜索的iPhone應用程序。我使用的是CoreData,它的工作原理非常漂亮,除了需要大約2秒來創建數據表。我將它編程爲在後臺執行搜索,並添加了一個微調器,但用戶體驗仍然不理想。我嘗試使用FMDB工作正常,但沒有更快。CoreData搜索速度太慢
本質上,我創建了我的xcdatamodel在迅速,添加我的條目,它工作正常。 (下面的代碼鍵入寫意,很抱歉,如果有錯別字)
我然後創建一個NSFetchedResultsController:
let moc =(UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
searchText: String? = "name contains[c] \"seachText\""
nsfr = NSFetchRequest(entityName: "Example")
nsfr.fetchBatchSize = 20
nsfr.predicate = NSPredicate(format: searchText!)
nsfrc = NSFetchedResultsController(fetchRequest: nsfr, managedObjectContext: moc, sectionNameKeyPath: "section", cacheName: nil)
在我的UITableViewController類(符合NSFetchedResultsControllerDelegate)
然後:
nsfrc.delegate = self
nsfrc.performFetch()
self.tableView.reloadData()
有什麼辦法來加速請求,比如哈希數據庫?任何縮小搜索範圍的方法?我的數據包含數千個句子,我希望能夠搜索其中的部分字符串。例如,「laz fo」應該找到「懶惰的棕色狐狸」。現在「azy own」也會找到字符串,這不是必需的。任何幫助,將不勝感激!即使將時間縮短一半也會很棒。