Search for a String Containing Special Characters

Q: How do I search for a string that contains special characters when using the documentUIDsMatchingString API?

A: The documentUIDsMatchingString API uses SQLite under the hood, and SQLite by default does not consider the hyphen as a searchable character. See the SQLite fts5 web page for more information.

The easiest way to workaround this SQLite limitation is to pass .matchExactPhrasesOnly in the options dictionary, like so:

Copy
1
2
3
4
5
6
let options = [PDFLibrary.Option.matchExactPhrasesOnly: true]
PSPDFKit.SDK.shared.library?.documentUIDs(matching: searchTerm, options: options, completionHandler: { searchString, resultSet in
    print(resultSet)
}, previewTextHandler: { searchString, resultSet in
    print(resultSet)
})
Copy
1
2
3
4
5
6
NSDictionary *options = @{ PSPDFLibraryOptionMatchExactPhrasesOnly: @YES };
[PSPDFKitGlobal.sharedInstance.library documentUIDsMatchingString:searchTerm options:options completionHandler:^(NSString *searchString, NSDictionary *resultSet) {
    NSLog(@"%@", resultSet);
} previewTextHandler:^(NSString * _Nonnull searchString, NSDictionary<NSString *,NSSet<PSPDFLibraryPreviewResult *> *> * _Nonnull resultSet) {
    NSLog(@"%@", resultSet);
}];

For more details, take a look at the following guides:

If your use case only requires you to search within a specific document instead of your entire library, consider using our text search feature.