This commit is contained in:
Chris Li 2016-07-11 17:17:45 -04:00
parent 7ae208c113
commit 5c97a4337c
14 changed files with 184 additions and 178 deletions

View File

@ -57,7 +57,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, OperationQueueDelegate {
func applicationDidBecomeActive(application: UIApplication) { func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(AppDelegate.recordActiveSession), userInfo: nil, repeats: false) NSTimer.scheduledTimerWithTimeInterval(60.0, target: self, selector: #selector(AppDelegate.recordActiveSession), userInfo: nil, repeats: false)
ZIMMultiReader.sharedInstance.rescan() ZimMultiReader.sharedInstance.scan()
} }
func applicationWillTerminate(application: UIApplication) { func applicationWillTerminate(application: UIApplication) {

View File

@ -186,7 +186,7 @@ class LibraryLocalTBVC: UITableViewController, NSFetchedResultsControllerDelegat
let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.delete) { (action, indexPath) -> Void in let delete = UITableViewRowAction(style: .Destructive, title: LocalizedStrings.delete) { (action, indexPath) -> Void in
guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return} guard let book = self.fetchedResultController.objectAtIndexPath(indexPath) as? Book else {return}
self.managedObjectContext.performBlock({ () -> Void in self.managedObjectContext.performBlock({ () -> Void in
if let id = book.id, let zimURL = ZIMMultiReader.sharedInstance.readers[id]?.fileURL { if let id = book.id, let zimURL = ZimMultiReader.sharedInstance.readers[id]?.fileURL {
FileManager.removeItem(atURL: zimURL) FileManager.removeItem(atURL: zimURL)
let indexFolderURL = zimURL.URLByAppendingPathExtension("idx") let indexFolderURL = zimURL.URLByAppendingPathExtension("idx")

View File

@ -45,7 +45,7 @@ class MainVC: UIViewController {
navigationItem.titleView = searchBar navigationItem.titleView = searchBar
searchBar.delegate = self searchBar.delegate = self
ZIMMultiReader.sharedInstance.delegate = self ZimMultiReader.sharedInstance.delegate = self
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewNotInjectJavascriptToAdjustPageLayout", options: .New, context: context) NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewNotInjectJavascriptToAdjustPageLayout", options: .New, context: context)
NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewZoomScale", options: .New, context: context) NSUserDefaults.standardUserDefaults().addObserver(self, forKeyPath: "webViewZoomScale", options: .New, context: context)

View File

@ -45,7 +45,7 @@ extension MainVC: LPTBarButtonItemDelegate, TableOfContentsDelegate, ZimMultiRea
// MARK: - ZimMultiReaderDelegate // MARK: - ZimMultiReaderDelegate
func firstBookAdded(id: ZIMID) { func firstBookAdded(id: ZimID) {
loadMainPage(id) loadMainPage(id)
} }

View File

@ -19,8 +19,8 @@ extension MainVC {
webView.loadRequest(request) webView.loadRequest(request)
} }
func loadMainPage(id: ZIMID) { func loadMainPage(id: ZimID) {
guard let reader = ZIMMultiReader.sharedInstance.readers[id] else {return} guard let reader = ZimMultiReader.sharedInstance.readers[id] else {return}
let mainPageURLString = reader.mainPageURL() let mainPageURLString = reader.mainPageURL()
let mainPageURL = NSURL.kiwixURLWithZimFileid(id, contentURLString: mainPageURLString) let mainPageURL = NSURL.kiwixURLWithZimFileid(id, contentURLString: mainPageURLString)
load(mainPageURL) load(mainPageURL)

View File

@ -120,7 +120,7 @@ class SearchResultTBVC: UIViewController, UITableViewDataSource, UITableViewDele
tableView.reloadData() tableView.reloadData()
return return
} }
ZIMMultiReader.sharedInstance.searchQueue.cancelAllOperations() ZimMultiReader.sharedInstance.searchQueue.cancelAllOperations()
let operation = SearchOperation(searchTerm: searchText) { (results) in let operation = SearchOperation(searchTerm: searchText) { (results) in
self.searchResults = results self.searchResults = results
self.tableView.reloadData() self.tableView.reloadData()
@ -128,7 +128,7 @@ class SearchResultTBVC: UIViewController, UITableViewDataSource, UITableViewDele
self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: .Top, animated: true) self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: .Top, animated: true)
} }
} }
ZIMMultiReader.sharedInstance.searchQueue.addOperation(operation) ZimMultiReader.sharedInstance.searchQueue.addOperation(operation)
} }
} }

View File

@ -21,7 +21,7 @@ class KiwixURLProtocol: NSURLProtocol {
override func startLoading() { override func startLoading() {
if let id = self.request.URL?.host, let contentURLString = self.request.URL?.path?.stringByRemovingPercentEncoding { if let id = self.request.URL?.host, let contentURLString = self.request.URL?.path?.stringByRemovingPercentEncoding {
if let dataDic = ZIMMultiReader.sharedInstance.data(id, contentURLString: contentURLString), if let dataDic = ZimMultiReader.sharedInstance.data(id, contentURLString: contentURLString),
data = dataDic["data"] as? NSData, data = dataDic["data"] as? NSData,
mimeType = dataDic["mime"] as? String, mimeType = dataDic["mime"] as? String,
dataLength = dataDic["length"]?.integerValue { dataLength = dataDic["length"]?.integerValue {
@ -53,14 +53,14 @@ extension NSURL {
} }
class func kiwixURLWithZimFileid(id: String, articleTitle: String) -> NSURL? { class func kiwixURLWithZimFileid(id: String, articleTitle: String) -> NSURL? {
guard let contentURLString = ZIMMultiReader.sharedInstance.pageURLString(articleTitle, bookid: id) else { guard let contentURLString = ZimMultiReader.sharedInstance.pageURLString(articleTitle, bookid: id) else {
print("ZimMultiReader cannot get pageURLString from \(articleTitle) in book \(id)") print("ZimMultiReader cannot get pageURLString from \(articleTitle) in book \(id)")
return nil return nil
} }
return NSURL.kiwixURLWithZimFileid(id, contentURLString: contentURLString) return NSURL.kiwixURLWithZimFileid(id, contentURLString: contentURLString)
} }
convenience init?(id: ZIMID, contentURLString: String) { convenience init?(id: ZimID, contentURLString: String) {
guard let escapedContentURLString = contentURLString.stringByAddingPercentEncodingWithAllowedCharacters(.URLPathAllowedCharacterSet()) else {return nil} guard let escapedContentURLString = contentURLString.stringByAddingPercentEncodingWithAllowedCharacters(.URLPathAllowedCharacterSet()) else {return nil}
let baseURLString = "kiwix://" + id let baseURLString = "kiwix://" + id
self.init(string: escapedContentURLString, relativeToURL: NSURL(string: baseURLString)) self.init(string: escapedContentURLString, relativeToURL: NSURL(string: baseURLString))

View File

@ -94,7 +94,6 @@
971A107F1D022F74007FC62C /* ImportBookLearnMore.html in Resources */ = {isa = PBXBuildFile; fileRef = 971A107B1D022F74007FC62C /* ImportBookLearnMore.html */; }; 971A107F1D022F74007FC62C /* ImportBookLearnMore.html in Resources */ = {isa = PBXBuildFile; fileRef = 971A107B1D022F74007FC62C /* ImportBookLearnMore.html */; };
971A10801D022F74007FC62C /* Pic_I.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107C1D022F74007FC62C /* Pic_I.png */; }; 971A10801D022F74007FC62C /* Pic_I.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107C1D022F74007FC62C /* Pic_I.png */; };
971A10811D022F74007FC62C /* Pic_P.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107D1D022F74007FC62C /* Pic_P.png */; }; 971A10811D022F74007FC62C /* Pic_P.png in Resources */ = {isa = PBXBuildFile; fileRef = 971A107D1D022F74007FC62C /* Pic_P.png */; };
97254FDF1C2644560056950B /* ZIMMultiReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97254FDE1C2644560056950B /* ZIMMultiReader.swift */; };
9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; }; 9734E54E1D289D060061C39B /* Welcome.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9734E54D1D289D060061C39B /* Welcome.storyboard */; };
973BCCEC1CEB3FA400F10B44 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCCEB1CEB3FA400F10B44 /* AppDelegate.swift */; }; 973BCCEC1CEB3FA400F10B44 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973BCCEB1CEB3FA400F10B44 /* AppDelegate.swift */; };
973BCCF31CEB3FA400F10B44 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 973BCCF21CEB3FA400F10B44 /* Assets.xcassets */; }; 973BCCF31CEB3FA400F10B44 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 973BCCF21CEB3FA400F10B44 /* Assets.xcassets */; };
@ -114,7 +113,10 @@
973DD4171D343F2F009D45DB /* liblzma.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40C1D343F2F009D45DB /* liblzma.a */; }; 973DD4171D343F2F009D45DB /* liblzma.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40C1D343F2F009D45DB /* liblzma.a */; };
973DD4181D343F2F009D45DB /* libxapian.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40D1D343F2F009D45DB /* libxapian.a */; }; 973DD4181D343F2F009D45DB /* libxapian.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40D1D343F2F009D45DB /* libxapian.a */; };
973DD4191D343F2F009D45DB /* libzim.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40E1D343F2F009D45DB /* libzim.a */; }; 973DD4191D343F2F009D45DB /* libzim.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 973DD40E1D343F2F009D45DB /* libzim.a */; };
974570F41C2DABB500680E43 /* ZIMMultiReaderAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974570F31C2DABB500680E43 /* ZIMMultiReaderAPI.swift */; }; 973DD41D1D34428F009D45DB /* DirectoryMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD41A1D34428F009D45DB /* DirectoryMonitor.swift */; };
973DD41E1D34428F009D45DB /* ZimMultiReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD41B1D34428F009D45DB /* ZimMultiReader.swift */; };
973DD4211D34434C009D45DB /* SearchResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4201D34434C009D45DB /* SearchResult.swift */; };
973DD4231D3443A3009D45DB /* ExtensionAndTypealias.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973DD4221D3443A3009D45DB /* ExtensionAndTypealias.swift */; };
975227821D020560001D1DDE /* Indexer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975227811D020560001D1DDE /* Indexer.storyboard */; }; 975227821D020560001D1DDE /* Indexer.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 975227811D020560001D1DDE /* Indexer.storyboard */; };
975227991D020C00001D1DDE /* indexer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975227921D020C00001D1DDE /* indexer.cpp */; settings = {COMPILER_FLAGS = "-w"; }; }; 975227991D020C00001D1DDE /* indexer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975227921D020C00001D1DDE /* indexer.cpp */; settings = {COMPILER_FLAGS = "-w"; }; };
9752279B1D020C00001D1DDE /* otherTools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975227931D020C00001D1DDE /* otherTools.cpp */; }; 9752279B1D020C00001D1DDE /* otherTools.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 975227931D020C00001D1DDE /* otherTools.cpp */; };
@ -145,9 +147,6 @@
975B90FF1CEB909900D13906 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9779987A1C1E1C9600B1DD5E /* Extensions.swift */; }; 975B90FF1CEB909900D13906 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9779987A1C1E1C9600B1DD5E /* Extensions.swift */; };
975B912F1CEB9B0F00D13906 /* Preference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973C8D5B1C25F945007272F9 /* Preference.swift */; }; 975B912F1CEB9B0F00D13906 /* Preference.swift in Sources */ = {isa = PBXBuildFile; fileRef = 973C8D5B1C25F945007272F9 /* Preference.swift */; };
9763A6291CEB9E55008A2718 /* OSXExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9763A6281CEB9E55008A2718 /* OSXExtensions.swift */; }; 9763A6291CEB9E55008A2718 /* OSXExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9763A6281CEB9E55008A2718 /* OSXExtensions.swift */; };
9763A62A1CEBA4F9008A2718 /* ZIMMultiReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97254FDE1C2644560056950B /* ZIMMultiReader.swift */; };
9763A62B1CEBA4F9008A2718 /* ZIMMultiReaderAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 974570F31C2DABB500680E43 /* ZIMMultiReaderAPI.swift */; };
9763A62C1CEBA4F9008A2718 /* DirectoryMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A714091C274FCB00951244 /* DirectoryMonitor.swift */; };
9763A62D1CEBA524008A2718 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E891681CA976E90001CA32 /* FileManager.swift */; }; 9763A62D1CEBA524008A2718 /* FileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E891681CA976E90001CA32 /* FileManager.swift */; };
976AB2671CBD8B3D00B06EB0 /* 1.5.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 976AB2661CBD8B3D00B06EB0 /* 1.5.xcmappingmodel */; }; 976AB2671CBD8B3D00B06EB0 /* 1.5.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = 976AB2661CBD8B3D00B06EB0 /* 1.5.xcmappingmodel */; };
977305361D0DFD110081B8F0 /* KiwixURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10711D022E74007FC62C /* KiwixURLProtocol.swift */; }; 977305361D0DFD110081B8F0 /* KiwixURLProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 971A10711D022E74007FC62C /* KiwixURLProtocol.swift */; };
@ -173,7 +172,6 @@
979CB6C81D05CF37005E1BA1 /* SearchResultController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979CB6C71D05CF37005E1BA1 /* SearchResultController.swift */; }; 979CB6C81D05CF37005E1BA1 /* SearchResultController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979CB6C71D05CF37005E1BA1 /* SearchResultController.swift */; };
979CB6CA1D05D26E005E1BA1 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979CB6C91D05D26E005E1BA1 /* WebViewController.swift */; }; 979CB6CA1D05D26E005E1BA1 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 979CB6C91D05D26E005E1BA1 /* WebViewController.swift */; };
97A7017F1D2C59CA00AAE2D8 /* GetStartedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A7017E1D2C59CA00AAE2D8 /* GetStartedController.swift */; }; 97A7017F1D2C59CA00AAE2D8 /* GetStartedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A7017E1D2C59CA00AAE2D8 /* GetStartedController.swift */; };
97A7140A1C274FCB00951244 /* DirectoryMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97A714091C274FCB00951244 /* DirectoryMonitor.swift */; };
97BA32A51CEBC36300339A47 /* RootWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97BA32A31CEBC29500339A47 /* RootWindowController.swift */; }; 97BA32A51CEBC36300339A47 /* RootWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97BA32A31CEBC29500339A47 /* RootWindowController.swift */; };
97D452BC1D16FF010033666F /* RecentSearchCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BB1D16FF010033666F /* RecentSearchCVC.swift */; }; 97D452BC1D16FF010033666F /* RecentSearchCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BB1D16FF010033666F /* RecentSearchCVC.swift */; };
97D452BE1D1723FF0033666F /* CollectionViewCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */; }; 97D452BE1D1723FF0033666F /* CollectionViewCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */; };
@ -335,7 +333,6 @@
971A107B1D022F74007FC62C /* ImportBookLearnMore.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = ImportBookLearnMore.html; path = Kiwix/HelpDocuments/ImportBookLearnMore.html; sourceTree = SOURCE_ROOT; }; 971A107B1D022F74007FC62C /* ImportBookLearnMore.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = ImportBookLearnMore.html; path = Kiwix/HelpDocuments/ImportBookLearnMore.html; sourceTree = SOURCE_ROOT; };
971A107C1D022F74007FC62C /* Pic_I.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Pic_I.png; path = Kiwix/HelpDocuments/Pic_I.png; sourceTree = SOURCE_ROOT; }; 971A107C1D022F74007FC62C /* Pic_I.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Pic_I.png; path = Kiwix/HelpDocuments/Pic_I.png; sourceTree = SOURCE_ROOT; };
971A107D1D022F74007FC62C /* Pic_P.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Pic_P.png; path = Kiwix/HelpDocuments/Pic_P.png; sourceTree = SOURCE_ROOT; }; 971A107D1D022F74007FC62C /* Pic_P.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Pic_P.png; path = Kiwix/HelpDocuments/Pic_P.png; sourceTree = SOURCE_ROOT; };
97254FDE1C2644560056950B /* ZIMMultiReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZIMMultiReader.swift; sourceTree = "<group>"; };
9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; }; 9734E54D1D289D060061C39B /* Welcome.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Welcome.storyboard; path = "Kiwix-iOS/Storyboard/Welcome.storyboard"; sourceTree = SOURCE_ROOT; };
973BCCE91CEB3FA400F10B44 /* Kiwix.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Kiwix.app; sourceTree = BUILT_PRODUCTS_DIR; }; 973BCCE91CEB3FA400F10B44 /* Kiwix.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Kiwix.app; sourceTree = BUILT_PRODUCTS_DIR; };
973BCCEB1CEB3FA400F10B44 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = "Kiwix-OSX/AppDelegate.swift"; sourceTree = SOURCE_ROOT; }; 973BCCEB1CEB3FA400F10B44 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = "Kiwix-OSX/AppDelegate.swift"; sourceTree = SOURCE_ROOT; };
@ -363,7 +360,10 @@
973DD40C1D343F2F009D45DB /* liblzma.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liblzma.a; path = Kiwix/libkiwix/iOS/liblzma.a; sourceTree = "<group>"; }; 973DD40C1D343F2F009D45DB /* liblzma.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liblzma.a; path = Kiwix/libkiwix/iOS/liblzma.a; sourceTree = "<group>"; };
973DD40D1D343F2F009D45DB /* libxapian.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libxapian.a; path = Kiwix/libkiwix/iOS/libxapian.a; sourceTree = "<group>"; }; 973DD40D1D343F2F009D45DB /* libxapian.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libxapian.a; path = Kiwix/libkiwix/iOS/libxapian.a; sourceTree = "<group>"; };
973DD40E1D343F2F009D45DB /* libzim.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libzim.a; path = Kiwix/libkiwix/iOS/libzim.a; sourceTree = "<group>"; }; 973DD40E1D343F2F009D45DB /* libzim.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libzim.a; path = Kiwix/libkiwix/iOS/libzim.a; sourceTree = "<group>"; };
974570F31C2DABB500680E43 /* ZIMMultiReaderAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZIMMultiReaderAPI.swift; sourceTree = "<group>"; }; 973DD41A1D34428F009D45DB /* DirectoryMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DirectoryMonitor.swift; path = ZimMultiReader/DirectoryMonitor.swift; sourceTree = "<group>"; };
973DD41B1D34428F009D45DB /* ZimMultiReader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ZimMultiReader.swift; path = ZimMultiReader/ZimMultiReader.swift; sourceTree = "<group>"; };
973DD4201D34434C009D45DB /* SearchResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SearchResult.swift; path = ZimMultiReader/SearchResult.swift; sourceTree = "<group>"; };
973DD4221D3443A3009D45DB /* ExtensionAndTypealias.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ExtensionAndTypealias.swift; path = ZimMultiReader/ExtensionAndTypealias.swift; sourceTree = "<group>"; };
97497B5A1D07487000ECD691 /* indexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = indexer.h; path = "Kiwix/libkiwix/C&C++/indexer.h"; sourceTree = "<group>"; }; 97497B5A1D07487000ECD691 /* indexer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = indexer.h; path = "Kiwix/libkiwix/C&C++/indexer.h"; sourceTree = "<group>"; };
97497B5B1D07487000ECD691 /* resourceTools.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = resourceTools.h; path = "Kiwix/libkiwix/C&C++/resourceTools.h"; sourceTree = "<group>"; }; 97497B5B1D07487000ECD691 /* resourceTools.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = resourceTools.h; path = "Kiwix/libkiwix/C&C++/resourceTools.h"; sourceTree = "<group>"; };
97497B5C1D074FB800ECD691 /* htmlparse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = htmlparse.h; path = "Kiwix/libkiwix/C&C++/xapian/htmlparse.h"; sourceTree = "<group>"; }; 97497B5C1D074FB800ECD691 /* htmlparse.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = htmlparse.h; path = "Kiwix/libkiwix/C&C++/xapian/htmlparse.h"; sourceTree = "<group>"; };
@ -419,7 +419,6 @@
97A2AB9F1C1B80FF00052E74 /* Kiwix-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Kiwix-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 97A2AB9F1C1B80FF00052E74 /* Kiwix-iOSTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Kiwix-iOSTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
97A2ABAA1C1B810000052E74 /* Kiwix-iOSUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Kiwix-iOSUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 97A2ABAA1C1B810000052E74 /* Kiwix-iOSUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Kiwix-iOSUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
97A7017E1D2C59CA00AAE2D8 /* GetStartedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GetStartedController.swift; path = "Kiwix-iOS/Controller/Welcome/GetStartedController.swift"; sourceTree = SOURCE_ROOT; }; 97A7017E1D2C59CA00AAE2D8 /* GetStartedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = GetStartedController.swift; path = "Kiwix-iOS/Controller/Welcome/GetStartedController.swift"; sourceTree = SOURCE_ROOT; };
97A714091C274FCB00951244 /* DirectoryMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DirectoryMonitor.swift; sourceTree = "<group>"; };
97BA32A31CEBC29500339A47 /* RootWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RootWindowController.swift; path = "Kiwix-OSX/Controllers/RootWindowController.swift"; sourceTree = SOURCE_ROOT; }; 97BA32A31CEBC29500339A47 /* RootWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RootWindowController.swift; path = "Kiwix-OSX/Controllers/RootWindowController.swift"; sourceTree = SOURCE_ROOT; };
97D452BB1D16FF010033666F /* RecentSearchCVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RecentSearchCVC.swift; path = "Kiwix-iOS/Controller/Search/RecentSearchCVC.swift"; sourceTree = SOURCE_ROOT; }; 97D452BB1D16FF010033666F /* RecentSearchCVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RecentSearchCVC.swift; path = "Kiwix-iOS/Controller/Search/RecentSearchCVC.swift"; sourceTree = SOURCE_ROOT; };
97D452BD1D1723FF0033666F /* CollectionViewCells.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCells.swift; sourceTree = "<group>"; }; 97D452BD1D1723FF0033666F /* CollectionViewCells.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CollectionViewCells.swift; sourceTree = "<group>"; };
@ -706,14 +705,15 @@
path = View; path = View;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
97254FDD1C26442F0056950B /* ZIMMultiReader */ = { 97254FDD1C26442F0056950B /* ZimMultiReader */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
97254FDE1C2644560056950B /* ZIMMultiReader.swift */, 973DD41B1D34428F009D45DB /* ZimMultiReader.swift */,
974570F31C2DABB500680E43 /* ZIMMultiReaderAPI.swift */, 973DD4201D34434C009D45DB /* SearchResult.swift */,
97A714091C274FCB00951244 /* DirectoryMonitor.swift */, 973DD4221D3443A3009D45DB /* ExtensionAndTypealias.swift */,
973DD41A1D34428F009D45DB /* DirectoryMonitor.swift */,
); );
name = ZIMMultiReader; name = ZimMultiReader;
path = Kiwix; path = Kiwix;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
@ -773,7 +773,7 @@
971A10711D022E74007FC62C /* KiwixURLProtocol.swift */, 971A10711D022E74007FC62C /* KiwixURLProtocol.swift */,
973C8D5B1C25F945007272F9 /* Preference.swift */, 973C8D5B1C25F945007272F9 /* Preference.swift */,
979C51511CECA9AF001707F2 /* StringTools.swift */, 979C51511CECA9AF001707F2 /* StringTools.swift */,
97254FDD1C26442F0056950B /* ZIMMultiReader */, 97254FDD1C26442F0056950B /* ZimMultiReader */,
); );
name = Shared; name = Shared;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1499,7 +1499,6 @@
9752279B1D020C00001D1DDE /* otherTools.cpp in Sources */, 9752279B1D020C00001D1DDE /* otherTools.cpp in Sources */,
975B912F1CEB9B0F00D13906 /* Preference.swift in Sources */, 975B912F1CEB9B0F00D13906 /* Preference.swift in Sources */,
971187941CEB541A00B9909D /* Article.swift in Sources */, 971187941CEB541A00B9909D /* Article.swift in Sources */,
9763A62B1CEBA4F9008A2718 /* ZIMMultiReaderAPI.swift in Sources */,
9752279D1D020C00001D1DDE /* pathTools.cpp in Sources */, 9752279D1D020C00001D1DDE /* pathTools.cpp in Sources */,
975227A91D020C2E001D1DDE /* myhtmlparse.cc in Sources */, 975227A91D020C2E001D1DDE /* myhtmlparse.cc in Sources */,
975227B01D021539001D1DDE /* IndexerController.swift in Sources */, 975227B01D021539001D1DDE /* IndexerController.swift in Sources */,
@ -1519,9 +1518,7 @@
971187971CEB542500B9909D /* Article+CoreDataProperties.swift in Sources */, 971187971CEB542500B9909D /* Article+CoreDataProperties.swift in Sources */,
975227A31D020C00001D1DDE /* stringTools.cpp in Sources */, 975227A31D020C00001D1DDE /* stringTools.cpp in Sources */,
977305361D0DFD110081B8F0 /* KiwixURLProtocol.swift in Sources */, 977305361D0DFD110081B8F0 /* KiwixURLProtocol.swift in Sources */,
9763A62A1CEBA4F9008A2718 /* ZIMMultiReader.swift in Sources */,
979C518D1CECAE4C001707F2 /* PreferenceWindowController.swift in Sources */, 979C518D1CECAE4C001707F2 /* PreferenceWindowController.swift in Sources */,
9763A62C1CEBA4F9008A2718 /* DirectoryMonitor.swift in Sources */,
9711879B1CEB546C00B9909D /* CoreDataExtension.swift in Sources */, 9711879B1CEB546C00B9909D /* CoreDataExtension.swift in Sources */,
979C51531CECA9AF001707F2 /* StringTools.swift in Sources */, 979C51531CECA9AF001707F2 /* StringTools.swift in Sources */,
971187931CEB541A00B9909D /* DownloadTask.swift in Sources */, 971187931CEB541A00B9909D /* DownloadTask.swift in Sources */,
@ -1561,6 +1558,7 @@
isa = PBXSourcesBuildPhase; isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
973DD41D1D34428F009D45DB /* DirectoryMonitor.swift in Sources */,
976AB2671CBD8B3D00B06EB0 /* 1.5.xcmappingmodel in Sources */, 976AB2671CBD8B3D00B06EB0 /* 1.5.xcmappingmodel in Sources */,
971A10311D022AD5007FC62C /* RefreshHUD.swift in Sources */, 971A10311D022AD5007FC62C /* RefreshHUD.swift in Sources */,
971A102C1D022AD5007FC62C /* BarButtonItems.swift in Sources */, 971A102C1D022AD5007FC62C /* BarButtonItems.swift in Sources */,
@ -1568,6 +1566,7 @@
971A103F1D022C42007FC62C /* LibraryAutoRefreshTBVC.swift in Sources */, 971A103F1D022C42007FC62C /* LibraryAutoRefreshTBVC.swift in Sources */,
971A10721D022E74007FC62C /* KiwixURLProtocol.swift in Sources */, 971A10721D022E74007FC62C /* KiwixURLProtocol.swift in Sources */,
971A10581D022DAD007FC62C /* LibraryDownloadTBVC.swift in Sources */, 971A10581D022DAD007FC62C /* LibraryDownloadTBVC.swift in Sources */,
973DD4231D3443A3009D45DB /* ExtensionAndTypealias.swift in Sources */,
97A7017F1D2C59CA00AAE2D8 /* GetStartedController.swift in Sources */, 97A7017F1D2C59CA00AAE2D8 /* GetStartedController.swift in Sources */,
979C51521CECA9AF001707F2 /* StringTools.swift in Sources */, 979C51521CECA9AF001707F2 /* StringTools.swift in Sources */,
9779A1CD1D34225E0071EFAB /* UIOperations.swift in Sources */, 9779A1CD1D34225E0071EFAB /* UIOperations.swift in Sources */,
@ -1577,7 +1576,6 @@
971A10651D022E0A007FC62C /* MainVC.swift in Sources */, 971A10651D022E0A007FC62C /* MainVC.swift in Sources */,
971A106F1D022E62007FC62C /* DownloadProgress.swift in Sources */, 971A106F1D022E62007FC62C /* DownloadProgress.swift in Sources */,
971A102E1D022AD5007FC62C /* TableViewCells.swift in Sources */, 971A102E1D022AD5007FC62C /* TableViewCells.swift in Sources */,
97254FDF1C2644560056950B /* ZIMMultiReader.swift in Sources */,
971A105A1D022DAD007FC62C /* LibraryLocalTBVC.swift in Sources */, 971A105A1D022DAD007FC62C /* LibraryLocalTBVC.swift in Sources */,
97E60A021D10423A00EBCB9D /* ShadowView.swift in Sources */, 97E60A021D10423A00EBCB9D /* ShadowView.swift in Sources */,
9779A1CC1D34225E0071EFAB /* SearchOperation.swift in Sources */, 9779A1CC1D34225E0071EFAB /* SearchOperation.swift in Sources */,
@ -1597,7 +1595,6 @@
97E891691CA976E90001CA32 /* FileManager.swift in Sources */, 97E891691CA976E90001CA32 /* FileManager.swift in Sources */,
97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */, 97E60A061D10504000EBCB9D /* LibraryBackupTBVC.swift in Sources */,
9779A1CA1D34225E0071EFAB /* NetworkObserver.swift in Sources */, 9779A1CA1D34225E0071EFAB /* NetworkObserver.swift in Sources */,
974570F41C2DABB500680E43 /* ZIMMultiReaderAPI.swift in Sources */,
971A105C1D022DAD007FC62C /* LibraryTabBarController.swift in Sources */, 971A105C1D022DAD007FC62C /* LibraryTabBarController.swift in Sources */,
971A10461D022CB2007FC62C /* SearchController.swift in Sources */, 971A10461D022CB2007FC62C /* SearchController.swift in Sources */,
9779987B1C1E1C9600B1DD5E /* Extensions.swift in Sources */, 9779987B1C1E1C9600B1DD5E /* Extensions.swift in Sources */,
@ -1622,7 +1619,6 @@
975227A21D020C00001D1DDE /* stringTools.cpp in Sources */, 975227A21D020C00001D1DDE /* stringTools.cpp in Sources */,
9711879A1CEB546C00B9909D /* CoreDataExtension.swift in Sources */, 9711879A1CEB546C00B9909D /* CoreDataExtension.swift in Sources */,
970C61971D34243600087758 /* URLSessionDownloadTaskOperation.swift in Sources */, 970C61971D34243600087758 /* URLSessionDownloadTaskOperation.swift in Sources */,
97A7140A1C274FCB00951244 /* DirectoryMonitor.swift in Sources */,
971A10341D022AEC007FC62C /* BookmarkTBVC.swift in Sources */, 971A10341D022AEC007FC62C /* BookmarkTBVC.swift in Sources */,
975227A01D020C00001D1DDE /* resourceTools.cpp in Sources */, 975227A01D020C00001D1DDE /* resourceTools.cpp in Sources */,
971A10601D022DF2007FC62C /* LanguageTBVC.swift in Sources */, 971A10601D022DF2007FC62C /* LanguageTBVC.swift in Sources */,
@ -1630,9 +1626,11 @@
971A106C1D022E50007FC62C /* Utilities.swift in Sources */, 971A106C1D022E50007FC62C /* Utilities.swift in Sources */,
971A10591D022DAD007FC62C /* LibraryLocalBookDetailTBVC.swift in Sources */, 971A10591D022DAD007FC62C /* LibraryLocalBookDetailTBVC.swift in Sources */,
971A10431D022C54007FC62C /* SettingTBVC.swift in Sources */, 971A10431D022C54007FC62C /* SettingTBVC.swift in Sources */,
973DD4211D34434C009D45DB /* SearchResult.swift in Sources */,
9779A1C91D34225E0071EFAB /* GlobalOperationQueue.swift in Sources */, 9779A1C91D34225E0071EFAB /* GlobalOperationQueue.swift in Sources */,
970C61991D3429E400087758 /* ReachabilityCondition.swift in Sources */, 970C61991D3429E400087758 /* ReachabilityCondition.swift in Sources */,
978C589C1C1CD86E0077AE47 /* Article.swift in Sources */, 978C589C1C1CD86E0077AE47 /* Article.swift in Sources */,
973DD41E1D34428F009D45DB /* ZimMultiReader.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -1941,7 +1939,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = ( LIBRARY_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Kiwix/libkiwix/static",
"$(PROJECT_DIR)/Kiwix/libkiwix/iOS", "$(PROJECT_DIR)/Kiwix/libkiwix/iOS",
); );
PRODUCT_BUNDLE_IDENTIFIER = self.Kiwix; PRODUCT_BUNDLE_IDENTIFIER = self.Kiwix;
@ -1976,7 +1973,6 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LIBRARY_SEARCH_PATHS = ( LIBRARY_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
"$(PROJECT_DIR)/Kiwix/libkiwix/static",
"$(PROJECT_DIR)/Kiwix/libkiwix/iOS", "$(PROJECT_DIR)/Kiwix/libkiwix/iOS",
); );
PRODUCT_BUNDLE_IDENTIFIER = self.Kiwix; PRODUCT_BUNDLE_IDENTIFIER = self.Kiwix;

View File

@ -21,7 +21,7 @@ class SearchOperation: GroupOperation {
self.results = results self.results = results
} }
for (id, zimReader) in ZIMMultiReader.sharedInstance.readers { for (id, zimReader) in ZimMultiReader.sharedInstance.readers {
let managedObjectContext = UIApplication.appDelegate.managedObjectContext let managedObjectContext = UIApplication.appDelegate.managedObjectContext
guard let book = Book.fetch(id, context: managedObjectContext) else {continue} guard let book = Book.fetch(id, context: managedObjectContext) else {continue}
guard book.includeInSearch else {continue} guard book.includeInSearch else {continue}

View File

@ -1,60 +0,0 @@
//
// ZIMMultiReaderAPI.swift
// Kiwix
//
// Created by Chris on 12/25/15.
// Copyright © 2015 Chris. All rights reserved.
//
extension ZIMMultiReader {
// MARK: - Search
func search(searchTerm: String, zimFileID: String) -> [(id: String, articleTitle: String)] {
var resultTuples = [(id: String, articleTitle: String)]()
let firstCharRange = searchTerm.startIndex...searchTerm.startIndex
let firstLetterCapitalisedSearchTerm = searchTerm.stringByReplacingCharactersInRange(firstCharRange, withString: searchTerm.substringWithRange(firstCharRange).capitalizedString)
let searchTermVariations = Set([searchTerm, searchTerm.uppercaseString, searchTerm.lowercaseString, searchTerm.capitalizedString, firstLetterCapitalisedSearchTerm])
let reader = readers[zimFileID]
var results = Set<String>()
for searchTermVariation in searchTermVariations {
guard let result = reader?.searchSuggestionsSmart(searchTermVariation) as? [String] else {continue}
results.unionInPlace(result)
}
for result in results {
resultTuples.append((id: zimFileID, articleTitle: result))
}
return resultTuples
}
// MARK: - Loading System
func data(id: String, contentURLString: String) -> [String: AnyObject]? {
guard let reader = readers[id] else {return nil}
return reader.dataWithContentURLString(contentURLString) as? [String: AnyObject]
}
func pageURLString(articleTitle: String, bookid id: String) -> String? {
guard let reader = readers[id] else {return nil}
return reader.pageURLFromTitle(articleTitle)
}
func mainPageURLString(bookid id: String) -> String? {
guard let reader = readers[id] else {return nil}
return reader.mainPageURL()
}
func randomPageURLString() -> (id: String, contentURLString: String)? {
var randomPageURLs = [(String, String)]()
for (id, reader) in readers{
randomPageURLs.append((id, reader.getRandomPageUrl()))
}
guard randomPageURLs.count > 0 else {return nil}
let index = arc4random_uniform(UInt32(randomPageURLs.count))
return randomPageURLs[Int(index)]
}
}

View File

@ -0,0 +1,32 @@
//
// ExtensionAndTypealias.swift
// Kiwix
//
// Created by Chris Li on 7/11/16.
// Copyright © 2016 Chris. All rights reserved.
//
import UIKit
extension ZimReader {
var metaData: [String: AnyObject] {
var metadata = [String: AnyObject]()
if let id = getID() {metadata["id"] = id}
if let title = getTitle() {metadata["title"] = title}
if let description = getDesc() {metadata["description"] = description}
if let creator = getCreator() {metadata["creator"] = creator}
if let publisher = getPublisher() {metadata["publisher"] = publisher}
if let favicon = getFavicon() {metadata["favicon"] = favicon}
if let date = getDate() {metadata["date"] = date}
if let articleCount = getArticleCount() {metadata["articleCount"] = articleCount}
if let mediaCount = getMediaCount() {metadata["mediaCount"] = mediaCount}
if let fileSize = getFileSize() {metadata["size"] = fileSize}
if let langCode = getLanguage() {metadata["language"] = langCode}
return metadata
}
}
typealias ZimID = String
typealias ArticlePath = String

View File

@ -0,0 +1,62 @@
//
// SearchResult.swift
// Kiwix
//
// Created by Chris Li on 7/11/16.
// Copyright © 2016 Chris. All rights reserved.
//
import UIKit
class SearchResult: CustomStringConvertible {
let title: String
let path: String
let bookID: ZimID
let snippet: String?
let probability: Double? // range: 0.0 - 1.0
let distance: Int // Levenshtein distance, non negative integer
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) ?? ""
let path = (rawResult["path"] as? String) ?? ""
let bookID = (rawResult["bookID"] as? ZimID) ?? ""
let snippet = rawResult["snippet"] as? String
let distance = (rawResult["distance"]as? NSNumber)?.integerValue ?? title.characters.count
let probability: Double? = {
if let probability = (rawResult["probability"] as? NSNumber)?.doubleValue {
return probability / 100.0
} else {
return nil
}
}()
self.title = title
self.path = path
self.bookID = bookID
self.snippet = snippet
self.probability = probability
self.distance = distance
if title == "" || path == "" || bookID == "" {return nil}
}
var description: String {
var parts = [bookID, title]
if let probability = probability {parts.append("\(probability)%")}
parts.append("dist: \(distance)")
return parts.joinWithSeparator(", ")
}
var rankInfo: String {
return "(\(distance), \(probability ?? -1), \(String(format: "%.4f", score)))"
}
}

View File

@ -1,5 +1,5 @@
// //
// ZIMMultiReader.swift // ZimMultiReader.swift
// Kiwix // Kiwix
// //
// Created by Chris on 12/19/15. // Created by Chris on 12/19/15.
@ -9,10 +9,10 @@
import CoreData import CoreData
import PSOperations import PSOperations
class ZIMMultiReader: NSObject, DirectoryMonitorDelegate { class ZimMultiReader: NSObject, DirectoryMonitorDelegate {
static let sharedInstance = ZIMMultiReader() static let sharedInstance = ZimMultiReader()
private(set) var readers = [ZIMID: ZimReader]() { private(set) var readers = [ZimID: ZimReader]() {
didSet { didSet {
if readers.count == 1 { if readers.count == 1 {
guard let id = readers.keys.first else {return} guard let id = readers.keys.first else {return}
@ -42,15 +42,15 @@ class ZIMMultiReader: NSObject, DirectoryMonitorDelegate {
// MARK: - DirectoryMonitorDelegate // MARK: - DirectoryMonitorDelegate
func directoryMonitorDidObserveChange() { func directoryMonitorDidObserveChange() {
rescan() scan()
} }
// MARK: - Refresh // MARK: - Scan
func rescan() { func scan() {
/* /*
If list of idx folders changes, reinitialize all zim readers, If list of idx folders changes, reinitialize all zim readers,
because currently ZIMMultiReader cannot find out which ZimReader's index folder is added or deleted because currently ZimMultiReader cannot find out which ZimReader's index folder is added or deleted
Note: when a idx folder is added, the content of that idx folder will not finish copying, which makes it meanless to detect idx folder addition. Note: when a idx folder is added, the content of that idx folder will not finish copying, which makes it meanless to detect idx folder addition.
Because, with a incompletely copied idx folder, the xapian initializer is guranteed to fail. So here only check for idx folder deletion. Because, with a incompletely copied idx folder, the xapian initializer is guranteed to fail. So here only check for idx folder deletion.
@ -147,83 +147,59 @@ class ZIMMultiReader: NSObject, DirectoryMonitorDelegate {
} }
return folderURLs return folderURLs
} }
// MARK: - Search
func search(searchTerm: String, zimFileID: String) -> [(id: String, articleTitle: String)] {
var resultTuples = [(id: String, articleTitle: String)]()
let firstCharRange = searchTerm.startIndex...searchTerm.startIndex
let firstLetterCapitalisedSearchTerm = searchTerm.stringByReplacingCharactersInRange(firstCharRange, withString: searchTerm.substringWithRange(firstCharRange).capitalizedString)
let searchTermVariations = Set([searchTerm, searchTerm.uppercaseString, searchTerm.lowercaseString, searchTerm.capitalizedString, firstLetterCapitalisedSearchTerm])
let reader = readers[zimFileID]
var results = Set<String>()
for searchTermVariation in searchTermVariations {
guard let result = reader?.searchSuggestionsSmart(searchTermVariation) as? [String] else {continue}
results.unionInPlace(result)
}
for result in results {
resultTuples.append((id: zimFileID, articleTitle: result))
}
return resultTuples
}
// MARK: - Loading System
func data(id: String, contentURLString: String) -> [String: AnyObject]? {
guard let reader = readers[id] else {return nil}
return reader.dataWithContentURLString(contentURLString) as? [String: AnyObject]
}
func pageURLString(articleTitle: String, bookid id: String) -> String? {
guard let reader = readers[id] else {return nil}
return reader.pageURLFromTitle(articleTitle)
}
func mainPageURLString(bookid id: String) -> String? {
guard let reader = readers[id] else {return nil}
return reader.mainPageURL()
}
func randomPageURLString() -> (id: String, contentURLString: String)? {
var randomPageURLs = [(String, String)]()
for (id, reader) in readers{
randomPageURLs.append((id, reader.getRandomPageUrl()))
}
guard randomPageURLs.count > 0 else {return nil}
let index = arc4random_uniform(UInt32(randomPageURLs.count))
return randomPageURLs[Int(index)]
}
} }
protocol ZimMultiReaderDelegate: class { protocol ZimMultiReaderDelegate: class {
func firstBookAdded(id: ZIMID) func firstBookAdded(id: ZimID)
} }
extension ZimReader {
var metaData: [String: AnyObject] {
var metadata = [String: AnyObject]()
if let id = getID() {metadata["id"] = id}
if let title = getTitle() {metadata["title"] = title}
if let description = getDesc() {metadata["description"] = description}
if let creator = getCreator() {metadata["creator"] = creator}
if let publisher = getPublisher() {metadata["publisher"] = publisher}
if let favicon = getFavicon() {metadata["favicon"] = favicon}
if let date = getDate() {metadata["date"] = date}
if let articleCount = getArticleCount() {metadata["articleCount"] = articleCount}
if let mediaCount = getMediaCount() {metadata["mediaCount"] = mediaCount}
if let fileSize = getFileSize() {metadata["size"] = fileSize}
if let langCode = getLanguage() {metadata["language"] = langCode}
return metadata
}
}
typealias ZIMID = String
class SearchResult: CustomStringConvertible {
let title: String
let path: String
let bookID: ZIMID
let snippet: String?
let probability: Double? // range: 0.0 - 1.0
let distance: Int // Levenshtein distance, non negative integer
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) ?? ""
let path = (rawResult["path"] as? String) ?? ""
let bookID = (rawResult["bookID"] as? ZIMID) ?? ""
let snippet = rawResult["snippet"] as? String
let distance = (rawResult["distance"]as? NSNumber)?.integerValue ?? title.characters.count
let probability: Double? = {
if let probability = (rawResult["probability"] as? NSNumber)?.doubleValue {
return probability / 100.0
} else {
return nil
}
}()
self.title = title
self.path = path
self.bookID = bookID
self.snippet = snippet
self.probability = probability
self.distance = distance
if title == "" || path == "" || bookID == "" {return nil}
}
var description: String {
var parts = [bookID, title]
if let probability = probability {parts.append("\(probability)%")}
parts.append("dist: \(distance)")
return parts.joinWithSeparator(", ")
}
var rankInfo: String {
return "(\(distance), \(probability ?? -1), \(String(format: "%.4f", score)))"
}
}