Search Method

Searches for the specified word or phrase in the recognized text of the specified page of a document.

expression.Search(pSearchCallback, ppiSearchResult)

*expression   * Required. An expression that returns an MiDocSearch object.

pSearchCallback    Required IMiSearchCallback. The IMiSearchCallback interface is hidden. Pass Nothing for this argument.

ppiSearchResult    Required IMiSelectableItem. An object variable that receives the search results.

Remarks

The Search method searches recognized text using the document, page, the search word or phrase, and the other search parameters specified in a prior call to the Initialize method. The Search method returns an IMiSelectableItem object, which exposes a Words collection. By using this collection, you can access the Count of found words and, through each individual Word object, the coordinates of the bounding rectangle that defines its location on the page.

The Search method only searches a single page as specified in the PageNum argument of the Initialize method. A loop is necessary in order to search all the pages of a document.

While it is possible to write your own search functionality (using string functions and the various properties that expose the text recognized by optical character recognition (OCR), the Office Document Imaging Search method uses a highly efficient "fuzzy search" algorithm.

Example

The following example initializes and runs a search of the recognized text of the first page in the document for the word or phrase entered in a text box named txtSearch, and then displays the results.

Sub TestSearch()

  Dim miDoc As MODI.Document
  Dim miSearch As MODI.MiDocSearch
  Dim miTextSel As MODI.IMiSelectableItem
  Dim strSearchInfo As String
  
  Set miDoc = New MODI.Document
  
  miDoc.Create "C:\document1.tif"
  
  miDoc.Images(0).OCR
  
  Set miSearch = New MODI.MiDocSearch
  miSearch.Initialize miDoc, txtSearch.Text, 0, 0, False, False
  miSearch.Search Nothing, miTextSel
  
  If miTextSel.Words.Count > 0 Then
    strSearchInfo = "The search found " & _
      miTextSel.Words.Count & _
      " instances of the search word(s)."
  Else
    strSearchInfo = "Search word(s) not found."
  End If
  MsgBox strSearchInfo, vbInformation + vbOKOnly, _
    "Search Information"
  
  Set miTextSel = Nothing
  Set miSearch = Nothing
  Set miDoc = Nothing

End Sub

Applies to | MiDocSearch Object