1. Home
  2. Foxit PDF SDK for iOS
  3. How to perform Indexed Full-Text Search in Foxit PDF SDK for iOS?

How to perform Indexed Full-Text Search in Foxit PDF SDK for iOS?

Foxit PDF SDK for iOS fully supports Indexed Full Text Search. To use this feature, follow the steps below:

  1. Get document source information. Create a document source based on a directory which will be used as the search directory.

    -(id)initWithDirectory: (NSString *)directory;
  2. Create a full text search object, and set a path of database to store the indexed data.

    -(id)init;
    -(void)setDataBasePath:(NSString *)path_of_data_base;
  3. Start to index the PDF documents which receive from the source.

    -(FSProgressive*)startUpdateIndex: (FSDocumentsSource*)source pause: (id<fspausecallback>)pause reUpdate:(BOOL)reUpdate;
    </fspausecallback>

    Note: You can index a specified PDF file. For example, if the contents of a PDF file have been changed, you can re-index it using the following API:

    -(BOOL)updateIndexWithFilePath: (NSString *)file_path;
  4. Search the specified keyword from the indexed data source. The search results will be returned to external by a specified callback function when a matched one is found.

    -(BOOL)searchOf: (NSString *)match_string rank_mode:(FSFullTextSearchRankMode)rank_mode callback: (id<fssearchcallback>)Callback;
    </fssearchcallback>

    Following is a sample of how to use it:

    - (void)FullTextSearch {
     
        NSString *directory = @"INPUT_DIRECTORY";
        FSDocumentsSource* docs = [[FSDocumentsSource alloc] initWithDirectory:directory];
        FSFullTextSearch* fulltextSearch = [FSFullTextSearch init];
     
    NSString* dbPath = @"The path of data base to store the indexed data...";
    [fulltextSearch setDataBasePath:dbPath];	
     
    FSProgressive* progressive = [fulltextSearch startUpdateIndex:docs pause:nil reUpdate:NO];
        if (progressive) {
            while (true) {
                if ([progressive resume] != FSProgressiveToBeContinued) {
                    break;
                }
            }
        }
     
        [fulltextSearch searchOf:@"Foxit" RankMode:FSFullTextSearchRankNone callback:[[FSSearchCallbackImp alloc] init]];
    }
     
    @end

    A sample callback function is as follows:

    @interface FSSearchCallbackImp: NSObject<fssearchcallback>
     
    @end
     
    @implementation FSSearchCallbackImp
     
    -(int)retrieveSearchResult:(NSString*)file_path page_index:(int)page_index match_result:(NSString*)match_result match_start_text_index:(int)match_start_text_index match_end_text_index:(int)match_end_text_index
    {
        NSLog (@"file_path: %@\n", file_path);
        NSLog (@"page_index: %i, match_start_text_index: %i, match_end_text_index: %i\n", page_index, match_start_text_index, match_end_text_index);
        NSLog (@"match_result: %@\n\n", match_result);
        return 0;
    }
     
    @end
    </fssearchcallback>

Note:

  • The indexed full text search provided by Foxit PDF SDK for Android will go through a directory recursively, so that both the files and the folders under the search directory will be indexed.
  • If you want to abort the index process, you can pass in a pause callback parameter to the startUpdateIndex interface. The callback function needToPauseNow will be invoked once a PDF document is indexed, so that the caller can abort the index process when the callback needToPauseNow return “true”.
  • The location of the indexed database is set by setDataBasePath interface. If you want to clear the indexed database, you shoud do it manually. And now, removing a file from index function is not supported.
  • Every search result of the searchOf interface is returned to external by a specified callback. Once the searchOf interface returns “true” or “false”, it means the searching is finished.
Updated on August 29, 2018

Was this article helpful?

Related Articles