Search for a String Containing Special Characters

When using the documentUIDsMatchingString API, it’s possible to search for a string that contains special characters. The documentUIDsMatchingString API uses SQLite under the hood, and by default, SQLite doesn’t consider the hyphen to be a searchable character. See the SQLite FTS5 webpage for more information.

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

let options = [PDFLibrary.Option.matchExactPhrasesOnly: true]
PSPDFKit.SDK.shared.library?.documentUIDs(matching: searchTerm, options: options, completionHandler: { searchString, resultSet in
}, previewTextHandler: { searchString, resultSet in
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, refer to 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.