Indexed Full-Text Search
Foxit PDF SDK for Android provides indexed full-text search (FTS) through the Core SDK. You can build an index database for PDFs in an offline directory and search efficiently across files—ideal for batch cross-file search.
Core Classes
| Class | Description |
|---|---|
FullTextSearch | FTS entry point; index management and search execution |
DocumentsSource | Document source; directory path to index (recursive subdirectories) |
SearchCallback | Search result callback; override retrieveSearchResult() for each match |
Sort Order Constants
| Constant | Value | Description |
|---|---|---|
e_RankNone | 0 | No sort; file traversal order |
e_RankHitCountASC | 1 | Ascending by hit count |
e_RankHitCountDESC | 2 | Descending by hit count |
Basic Flow
- Create
DocumentsSourcewith the scan directory - Create
FullTextSearchand set the index database path withsetDataBasePath() - Call
startUpdateIndex()to build or update the index (returnsProgressivefor progressive execution; setreUpdatetotrueto rebuild entirely) - Call
searchOf()to search; results arrive viaSearchCallback.retrieveSearchResult()
SearchCallback
Extend SearchCallback and override:
java
public int retrieveSearchResult(
String filePath, // File path of the match
int pageIndex, // Page index
String matchResult, // Matched text
int matchStartTextIndex, // Start character index
int matchEndTextIndex, // End character index
String sentence, // Full sentence
int matchSentenceStartTextIndex, // Sentence start index
int matchSentenceEndTextIndex // Sentence end index
)Return 0 to continue; return non-zero to stop.
Complete Example
java
import com.foxit.sdk.fts.FullTextSearch;
import com.foxit.sdk.fts.DocumentsSource;
import com.foxit.sdk.fts.SearchCallback;
import com.foxit.sdk.common.Progressive;
import com.foxit.sdk.common.fxcrt.PauseCallback;
FullTextSearch search = new FullTextSearch();
search.setDataBasePath("/sdcard/fts_index_db");
DocumentsSource source = new DocumentsSource("/sdcard/PDFDocuments");
// Build index
PauseCallback pause = new PauseCallback() {
@Override
public boolean needToPauseNow() { return false; }
};
Progressive progressive = search.startUpdateIndex(source, pause, false);
int state = Progressive.e_ToBeContinued;
while (state == Progressive.e_ToBeContinued) {
state = progressive.resume();
}
// Search
search.searchOf("foxit", FullTextSearch.e_RankHitCountDESC, new SearchCallback() {
@Override
public int retrieveSearchResult(String filePath, int pageIndex,
String matchResult, int matchStartTextIndex, int matchEndTextIndex,
String sentence, int matchSentenceStartTextIndex, int matchSentenceEndTextIndex) {
Log.d("FTS", "File: " + filePath + ", Page: " + pageIndex + ", Match: " + matchResult);
return 0;
}
});Notes
- The SDK recursively scans the directory and indexes all PDF files.
- Return
truefromPauseCallback.needToPauseNow()to pause indexing. - Removing a single file from the index is not supported; rebuild with
reUpdateset totrue.
API Reference
See the API Reference for full FullTextSearch, DocumentsSource, and SearchCallback documentation.