Indexed full-text search
Foxit PDF SDK for iOS provides cross-document indexed full-text search via Core SDK. Build an index over multiple PDFs first, then search quickly—ideal for large document sets.
Core classes
| Class | Description |
|---|---|
FSFullTextSearch | Full-text search engine: index build and search |
FSDocumentsSource | Document source for indexing |
FSSearchCallback | Callback per match |
Ranking modes
| Constant | Description |
|---|---|
FSFullTextSearchRankModeNone | No ranking |
FSFullTextSearchRankModeHitCount | Rank by hit count |
Example: build index and search
Step 1: Create engine and set index database path
objc
#import <FoxitRDK/FSPDFObjC.h>
FSFullTextSearch *fullTextSearch = [[FSFullTextSearch alloc] init];
// Index database path
NSString *dbPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES).firstObject
stringByAppendingPathComponent:@"search_index"];
[fullTextSearch setDataBasePath:dbPath];Step 2: Build or update index
objc
// Update index for one file
[fullTextSearch updateIndexWithFilePath:@"path/to/Sample.pdf"];Batch indexing asynchronously:
objc
FSDocumentsSource *source = ...; // Configure document source
FSProgressive *progressive = [fullTextSearch startUpdateIndex:source
pause:nil
reupdate:NO];
FSProgressiveState state = [progressive resume];
while (state == FSProgressiveToBeContinued) {
state = [progressive resume];
}
if (state == FSProgressiveFinished) {
NSLog(@"索引建立完成");
}Step 3: Search
Implement FSSearchCallback:
objc
@interface MySearchCallback : NSObject <FSSearchCallback>
@end
@implementation MySearchCallback
- (int)retrieveWithFile_path:(NSString *)filePath pageIndex:(int)pageIndex
matchResult:(NSString *)matchResult matchStartCharIndex:(int)matchStartCharIndex
matchEndCharIndex:(int)matchEndCharIndex {
NSLog(@"在文件 %@ 的第 %d 页找到: %@", filePath, pageIndex, matchResult);
return 0; // 0 = continue; non-zero = stop
}
@endRun search:
objc
MySearchCallback *callback = [[MySearchCallback alloc] init];
BOOL result = [fullTextSearch searchOf:@"搜索关键词"
rank_mode:FSFullTextSearchRankModeNone
callback:callback];Important
Indexing must run before search. The first index build can take time—run it on a background thread. After the database exists, searches are fast.
API reference
See the API reference for FSFullTextSearch and FSSearchCallback.