How to search by information in metadata


This tip demonstrates how to see if a metadata element exists; how to examine the values of predefined metadata elements, a user-defined metadata element, or any/all metadata elements; how to look for text within a metadata element's value or look for an exact value; and how to do a case-sensitive text comparison.
You could use a macro like this to define and execute a search that you run periodically. To end the search before it has finished, click the Search button on the Standard toolbar and then click Stop.

How to use

  1. Paste this macro into VBA.
  2. Change the path.
  3. Change the location where the search should begin.
  4. Run the macro.
[VBA]
Sub TextInMetadata()
    
    'create a new query object to define search criteria
    Dim pQ As IQuery
    Set pQ = New FileSystemQuery
    
    'see if predefined metadata element's value contains the specified text. Both FGDC and
    'ISO elements associated with the predefined element will be searched, if appropriate.
    pQ.AddFieldQuery esriFindFieldTypeTitle, esriFindFieldOperatorIncludes, "cities", ""
    
    'see if text exists in any metadata element's value
    pQ.AddFieldQuery esriFindFieldTypeFullText, esriFindFieldOperatorIncludes, "REQUIRED:", ""
    
    'see if user-defined metadata element's value exactly matches the specified text
    pQ.AddFieldQuery esriFindFieldTypeUserDefined, esriFindFieldOperatorEquals, "Published", "Esri/PublishStatus"
    
    'see if metadata element exists in the metadata. The element's value isn't examined.
    pQ.AddFieldQuery esriFindFieldTypeUserDefined, esriFindFieldOperatorExists, "", "Binary/Thumbnail"
    
    'do a case-sensitive text comparison. By default, text comparisons are not case-sensitive.
    'This setting will not be remembered from one search to the next.
    pQ.IsCaseSensitive = True
    
    'get the Search dialog box object, then get the available search engines
    Dim i As Integer
    Dim pFD As IFindDialog
    Dim pSE As ISearchEngine
    Dim pSEP As ISearchEngineProperties
    Set pFD = New FindDialog
    For i = 0 To (pFD.GetNumSearchEngines - 1)
        Set pSE = pFD.getSearchEngine(i)
        Select Case pSE.Name
            
            Case "Catalog"
                'enable the Catalog search engine. Because these search criteria can only be
                'evaluated using metadata, data will be found only if it has metadata.
                pSE.Enabled = True
                
                'search a local disk
                Set pSEP = pSE
                pSEP.LocationString = "C:\data"
                
            Case Else
                'disable other search engines
                pSE.Enabled = False
                
        End Select
    Next
    
    'initialize search components, then execute the search
    pFD.Show False
    pFD.DoSearch pQ
    
End Sub