Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ brew "curl"

at_exit do
system "pre-commit install"
system "curl -L -o - https://download.kiwix.org/release/libkiwix/libkiwix_xcframework-14.1.1.tar.gz | tar -x --strip-components 2"
system "curl -L -o - https://download.kiwix.org/release/libkiwix/libkiwix_xcframework-14.0.0-1.tar.gz | tar -x --strip-components 2"
# Copy Clang module map to xcframework for Swift C++ Interoperability
system "cp Support/CoreKiwix.modulemap CoreKiwix.xcframework/ios-arm64/Headers/module.modulemap"
system "cp Support/CoreKiwix.modulemap CoreKiwix.xcframework/ios-arm64_x86_64-simulator/Headers/module.modulemap"
Expand Down
14 changes: 9 additions & 5 deletions Model/Hotspot/KiwixHotspot.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,16 @@ - (Boolean) startFor: (nonnull NSSet *) zimFileIDs onPort: (int) port {
}

- (NSString *_Nullable) address {
std::vector<std::string> urls = self.server->getServerAccessUrls();
if (urls.size() > 0) {
return [NSString stringWithUTF8String: urls[0].c_str()];
NSString *ipAddress = [NSString stringWithUTF8String: self.server->getAddress().addr.c_str()];
return [NSString stringWithFormat:@"http://%@%@/", ipAddress, [self portNumberSuffix]];
}

- (NSString *) portNumberSuffix {
int portNumber = self.server->getPort();
if(portNumber == 80) {
return @"";
} else {
NSLog(@"no hotspot url was found");
return nil;
return [NSString stringWithFormat: @":%i", portNumber];
}
}

Expand Down
24 changes: 0 additions & 24 deletions Model/ZimFileService/SpellingsDBWrapper.h

This file was deleted.

32 changes: 0 additions & 32 deletions Model/ZimFileService/SpellingsDBWrapper.mm

This file was deleted.

5 changes: 0 additions & 5 deletions Model/ZimFileService/ZimFileService.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#import <Foundation/Foundation.h>
#import "ZimFileMetaData.h"
#import "zim/archive.h"
#import "SpellingsDBWrapper.h"

@interface ZimFileService : NSObject

Expand All @@ -35,10 +34,6 @@
- (zim::Archive *_Nullable) archiveBy: (NSUUID *_Nonnull) zimFileID;
- (zim::Archive *_Nullable) findArchiveBy: (NSUUID *_Nonnull) zimFileID;
- (nonnull void *) getArchives;
- (SpellingsDBWrapper *_Nullable)spellingsDBFor:(NSUUID *_Nonnull)zimFileID cachePath:(NSString *_Nonnull)contentPath;

# pragma mark - Spelling
- (void) createSpellingIndex: (NSUUID *_Nonnull) zimFileID cachePath:(NSString *_Nonnull)contentPath NS_REFINED_FOR_SWIFT;

# pragma mark - Metadata

Expand Down
36 changes: 3 additions & 33 deletions Model/ZimFileService/ZimFileService.mm
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,6 @@ - (nonnull void *) getArchives {
return self.archives;
}

# pragma mark - Spelling
- (SpellingsDBWrapper *_Nullable)spellingsDBFor:(NSUUID *)zimFileID cachePath:(NSString *)contentPath {

zim::Archive *archive = [self archiveBy: zimFileID];
if (archive == nil) {
NSLog(@"cannot find ZIM by ID: %@ (%@)", zimFileID.UUIDString, contentPath);
return nil;
}
try {
@synchronized (self) {
NSLog(@"createSpellingIndex for:%@, in: %@", zimFileID.UUIDString, contentPath);
// this should be safe for utf-8, it comes from swift URL.path(percentEncoded=True)
std::filesystem::path path = std::filesystem::path([contentPath cStringUsingEncoding: NSUTF8StringEncoding]);
auto db = std::make_unique<kiwix::SpellingsDB>(*archive, path);
SpellingsDBWrapper *wrapper = [[SpellingsDBWrapper alloc] initWithDB: std::move(db)];
return wrapper;
}
} catch (std::exception e) {
NSLog(@"create spelling index exception: %s", e.what());
return nil;
} catch (Xapian::DatabaseError e) {
NSLog(@"create spelling index exception no database found: %s", e.get_description().c_str());
return nil;
}
}

- (void) createSpellingIndex:(NSUUID *)zimFileID cachePath:(NSString *)contentPath {
[self spellingsDBFor:zimFileID cachePath:contentPath];
}

# pragma mark - Metadata

+ (ZimFileMetaData *_Nullable)getMetaDataWithFileURL:(NSURL *)url {
Expand Down Expand Up @@ -255,10 +225,10 @@ - (NSDictionary *)getContent:(NSUUID *)zimFileID contentPath:(NSString *)content
- (NSDictionary *_Nullable) getDirectAccess: (NSUUID *)zimFileID contentPath:(NSString *)contentPath {
try {
zim::Item item = [self itemIn:zimFileID contentPath: contentPath];
zim::ItemDataDirectAccessInfo info = item.getDirectAccessInformation();
zim::Item::DirectAccessInfo info = item.getDirectAccessInformation();
return @{
@"path": [NSString stringWithUTF8String: info.filename.c_str()],
@"offset": [NSNumber numberWithUnsignedLong: info.offset]
@"path": [NSString stringWithUTF8String: info.first.c_str()],
@"offset": [NSNumber numberWithUnsignedLong: info.second]
};
} catch(std::exception) {
return nil;
Expand Down
4 changes: 0 additions & 4 deletions Model/ZimFileService/ZimFileService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@
func openArchive(zimFileID: UUID) -> UUID? {
__open(zimFileID)
}

func createSpellingIndex(zimFileID: UUID, cacheDir: URL) {
__createSpellingIndex(zimFileID, cachePath: cacheDir.path())
}

/// Close a zim file
/// - Parameter fileID: ID of the zim file to close
Expand Down
1 change: 0 additions & 1 deletion SwiftUI/Model/SearchOperation/SearchOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ NS_ASSUME_NONNULL_BEGIN

- (id)initWithSearchText:(NSString *)searchText zimFileIDs:(NSSet *)zimFileIDs withSpellingCacheDir: (NSURL *_Nullable) spellCacheDir;
- (void)performSearch;
- (void) addSpellingCorrections NS_REFINED_FOR_SWIFT;

@end

Expand Down
27 changes: 0 additions & 27 deletions SwiftUI/Model/SearchOperation/SearchOperation.mm
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,6 @@ -(void) addResult: (SearchResult *_Nonnull) searchResult {
[self.results addObject: searchResult];
}

# pragma mark - Spelling

- (void) addSpellingCorrections {
[self.corrections removeAllObjects];
NSString *contentPath = [self.spellCacheDir path];
// apply for the list of ZimFileIds that are included in search
for (NSUUID *zimFileID in self.zimFileIDs) {
if (self.isCancelled) { return; }
try {
SpellingsDBWrapper *dbWrapper = [[ZimFileService sharedInstance] spellingsDBFor:zimFileID cachePath:contentPath];
if(dbWrapper == nil) {
return;
}
std::vector<std::string> spellCorrections = dbWrapper.cppDB->getSpellingCorrections(self.searchText_C, 1);
NSArray *array = convertToArray(spellCorrections);
if (self.isCancelled) { return; }
[self.corrections addObjectsFromArray:array];
NSInteger count = array.count;
NSLog(@"addSpellingCorrections for %@: (%ld)", zimFileID, static_cast<long>(count));
} catch (std::exception &e) {
NSLog(@"spellingsCorrections exception: %s", e.what());
} catch (Xapian::DatabaseError e) {
NSLog(@"create spelling index exception no database found: %s", e.get_description().c_str());
}
}
}

NSArray<NSString *> *convertToArray(const std::vector<std::string> &vec) {
NSMutableArray<NSString *> *result = [NSMutableArray new];
for (const std::string &s : vec) {
Expand Down
1 change: 0 additions & 1 deletion SwiftUI/Model/SearchOperation/SearchOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ extension SearchOperation {
return
}
Log.LibraryOperations.debug("perfoming search suggestsion")
__addSpellingCorrections()
let count: Int = __corrections.count
Log.LibraryOperations.debug("found search suggestsion: \(count, privacy: .public)")
}
Expand Down
1 change: 0 additions & 1 deletion ViewModel/SearchViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ final class SearchViewModel: NSObject, ObservableObject, NSFetchedResultsControl
if FileManager.default.fileExists(atPath: tempFile.path()) {
try? FileManager.default.removeItem(at: tempFile)
}
ZimFileService.shared.createSpellingIndex(zimFileID: zimFileID, cacheDir: cacheDir)
}
}
let operation = SearchOperation(
Expand Down
Loading