@@ -53,7 +53,10 @@ public override void ViewDidAppear(bool animated)
53
53
public void libraryDidFinishIndexing ( )
54
54
{
55
55
var searchstring = "" ;
56
- NSDictionary dic = null ;
56
+
57
+ // You can set some options for the search
58
+ var options = new NSMutableDictionary < NSObject , NSString > ( ) ;
59
+ options [ PSPDFLibrarySearchResultsOptionsKeys . MatchExactPhrasesOnlyKey ] = new NSString ( "YES" ) ;
57
60
58
61
var alert = UIAlertController . Create ( "" , "Start Full-Text Search with String:" , UIAlertControllerStyle . Alert ) ;
59
62
@@ -68,24 +71,35 @@ public void libraryDidFinishIndexing()
68
71
// Create a new alert controller for our results (cheap way to display them on the view)
69
72
var resultsAlert = UIAlertController . Create ( "" , "" , UIAlertControllerStyle . Alert ) ;
70
73
71
- library . FindDocumentUids ( searchstring , dic , ( string searchString , NSDictionary < NSString , NSIndexSet > resultSet ) =>
74
+ library . FindDocumentUids ( searchstring , options , ( string searchString , NSDictionary < NSString , NSIndexSet > resultSet ) =>
72
75
{
73
- string results = "" ;
74
76
foreach ( ( var UID , var indexSet ) in resultSet )
75
77
{
76
- // Get all the results into a single string so we can display them all at once
77
- results += string . Format ( "Found the following matches for \" {0}\" in document {1}: {2}\n \n " , searchstring , UID , indexSet ) ;
78
+ Console . WriteLine ( "Found the following matches for \" {0}\" in document {1}: {2}\n \n " , searchstring , UID , indexSet ) ;
78
79
}
79
- // Need to present the alert controller on the UI thread otherwise it crashes
80
+ } , ( string searchString , NSDictionary < NSString , NSSet < PSPDFLibraryPreviewResult > > resultSet ) =>
81
+ {
82
+ // Use the `previewTextHandler` for presenting preview text of the search results
80
83
DispatchQueue . MainQueue . DispatchAsync ( ( ) =>
81
84
{
82
- resultsAlert . Message = results ;
85
+ var previewTexts = "" ;
86
+ foreach ( var UID in resultSet . Keys )
87
+ {
88
+ // Get the results for each document
89
+ var results = resultSet [ UID ] ;
90
+
91
+ foreach ( PSPDFLibraryPreviewResult result in results )
92
+ {
93
+ // Get all the important information from each result
94
+ previewTexts += string . Format ( "Document: \" {0}\" \n Page: {1}\n Preview Text: \" {2}\" \n \n " , result . DocumentUid , ( result . PageIndex + 1 ) , result . PreviewText ) ;
95
+ }
96
+ }
97
+
98
+ resultsAlert . Message = previewTexts ;
83
99
resultsAlert . AddAction ( cancelAction ) ;
84
100
PresentViewController ( resultsAlert , false , null ) ;
85
101
} ) ;
86
-
87
102
} ) ;
88
-
89
103
} ) ;
90
104
91
105
alert . AddAction ( cancelAction ) ;
0 commit comments