Previous in Contents Next in Contents

Creating and Accessing IBuildCatalog Interface Objects

You create a new IBuildCatalog interface object by calling the IBuildCatalogs.Add method. You can access a specific IBuildCatalog interface object by calling the Item method. Because IBuildCatalogs is a collection, you can access all IBuildCatalog objects using a for each loop, as in the following example, where objBuildCatalog is the name you give the IBuildCatalog interface object:

Option Explicit 
On Error Resume Next

const Notification = 0

Dim objSearchAdmin, objBuildCatalog 
Dim objCurBldProps, objPrevBldProps, objProtocol 
Dim objColumn, objServer, objSite, objStartPage
Dim Prompt, Buttons, Title, Response

Buttons = vbYesNo + vbDefaultButton2 + vbExclamation + vbSystemModal
Title = "Search Build"

Sub TryStartBld(Catalog)
  Prompt   = "Would you like to build " & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.StartBuild
End Sub

Sub TryIncrementBld(Catalog)
  Prompt   = "Would you like to incrementally build " _
    & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.StartIncrementalBuild
End Sub

Sub TryStopBld(Catalog)
  Prompt   = "Would you like to stop building " _
    & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.StopBuild
End Sub

Sub TryPauseBld(Catalog)
  Prompt   = "Would you like to pause building " _
    & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.PauseBuild
End Sub

Sub TryResumeBld(Catalog)
  Prompt   = "Would you like to resume building " _
    & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.ResumeBuild
End Sub

Sub TryAbortBld(Catalog)
  Prompt   = "Would you like to abort propagating " _
    & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.AbortProp
End Sub

Sub TryForceProp(Catalog)
  Prompt   = "Would you like to propagate " _
    & Catalog.Name & "?"
  Response = MsgBox(Prompt, Buttons, Title)

  If Response = vbYes Then Catalog.ForceProp
End Sub

Set objSearchAdmin = CreateObject("Search.SearchAdmin.1")

'Add new catalog definition
objSearchAdmin.BuildServer.BuildCatalogs.Add "SampleCatalog", _
  "C:\Catalogs" 

For Each objBuildCatalog in objSearchAdmin.BuildServer.BuildCatalogs
  Wscript.Echo "Statistics for " & objBuildCatalog.Name _
    & " catalog definition:"

  Wscript.Echo "  Status: " & objBuildCatalog.Status

  Select Case objBuildCatalog.StatusCode 
    Case 0   ' Idle, no catalog build is in progress
      ' See if user wants to build or propagate the catalog 
      TryStartBld(objBuildCatalog)

      If Response = vbNo Then IncrementBld(objBuildCatalog)

      If Response = vbNo Then TryForceProp(objBuildCatalog)
    Case 1  ' Crawling, a build is in progress
      ' See if user wants to stop or pause build 
      TryStopBld(objBuildCatalog)
      If Response = vbNo Then TryPauseBld(objBuildCatalog)
    Case 2  ' Paused, the build is paused
      ' See if user wants to resume or stop the build
     TryResumeBld(objBuildCatalog)

      If Response = vbNo Then TryStopBld(objBuildCatalog)
    Case 3  ' Throttled, the build is temporarily paused 
            ' while Search performs another action
      ' See if user wants to stop or pause the build
      TryStopBld(objBuildCatalog)
      
      If Response = vbNo Then TryPauseBld(objBuildCatalog)
    Case 4  ' Initializing, the catalog build server is starting
      ' See if user wants to stop or pause the build
      TryStopBld(objBuildCatalog)
      
      If Response = vbNo Then TryPauseBld(objBuildCatalog)
    Case 5  ' Shut down, the catalog is being deleted
    Case 6  ' Crawling incrementally, an incremental build is in progress
      ' See if user wants to stop or pause build
      TryStopBld(objBuildCatalog)
      
      If Response = vbNo Then TryPauseBld(objBuildCatalog)
    Case 32  ' (Index) crawling, Search is indexing the documents
    Case 64  ' Compiling, Search is assembling the catalog
    Case 128  ' Propagating, Search is propagating the 
              ' catalog to the search servers on selected hosts
      ' See if user wants to abort the propagation
      TryAbortBld(objBuildCatalog)
    Case 320  ' Paused (disk full), the build is paused and 
              ' cannot continue until more disk space is made available 
      ' See if user wants to abort the propagation
      TryAbortBld(objBuildCatalog)
    Case 640  ' Retrying propagation, Search is trying to 
              ' propagate the catalog again after a failed attempt
      ' See if user wants to halt propagation
      TryAbortBld(objBuildCatalog)
    Case 1024  ' Flushing, Search has finished indexing the 
               ' documents and is flushing them from its cache
  End Select

  Wscript.Echo ""

  If objBuildCatalog.AutoPropLimitEnabled Then
    Wscript.Echo "  Propagates when a maximum of " _
      & objBuildCatalog.AutoPropLimit & " documents are crawled"
  End If

  If objBuildCatalog.Extensions.IncludedExtensions Then
    Wscript.Echo "  Includes " & objBuildCatalog.Extensions.Count _
    & " extensions"
  Else
    Wscript.Echo "  Excludes " & objBuildCatalog.Extensions.Count _
      & " extensions"
  End If

  If objBuildCatalog.FollowComplexUrls Then
    Wscript.Echo "  Allows wildcards in URLs"
  Else
    Wscript.Echo "  Does not allow wildcards in URLs"
  End If

  If objBuildCatalog.IsBuilding Then
    Wscript.Echo "  Is currently building pages: " _
      & objBuildCatalog.CurrentPages
  End If

  If objBuildCatalog.IsLocalFileSchema Then
    Wscript.Echo "  Uses the local schema file"
  Else
    Wscript.Echo "  Uses the default global schema file"
  End If

  If objBuildCatalog.LogExcluded Then
    Wscript.Echo "  Logs documents excluded from crawling"
  Else
    Wscript.Echo "  Does not log documents excluded from crawling"
  End If

  Wscript.Echo "  Has " & objBuildCatalog.Logs.Count & " logs"

  If objBuildCatalog.LogSuccess Then
    Wscript.Echo "  Logs documents successfully crawled"
  Else
    Wscript.Echo "  Does not log documents successfully crawled"
  End If

  Wscript.Echo "  Has " & objBuildCatalog.Mappings.Count & " mappings"

  If objBuildCatalog.ProjectType = Notification Then 
    Wscript.Echo "    Is a Notification project with " _
      & objBuildCatalog.NotificationSource & " identifier"
  Else
    Wscript.Echo "  Is a Crawl project"
  End If

  Wscript.Echo ""

  For Each objProtocol in objBuildCatalog.Protocols
    If objProtocol.Included Then
      Wscript.Echo "    Search uses protocol " & objProtocol.Urlname _
        & " when crawling"
    Else
      Wscript.Echo "    Search does not use protocol " _
        & objProtocol.Urlname & " when crawling"
    End If
  Next

  Wscript.Echo ""

  Wscript.Echo "  The schema contains the following fields:"

  For Each objColumn in objBuildCatalog.Schema.Columns
    If objColumn.Index Then
      Wscript.Echo "    " & objColumn.Name & " is indexed"
    End If
  Next

  Wscript.Echo ""

  If objBuildCatalog.SearchServers.Count > 0 Then
    Wscript.Echo "  The catalog is propagated to the following hosts:"

    For Each objServer in objBuildCatalog.SearchServers
      Wscript.Echo "    " & objServer.Name
    Next

    Wscript.Echo ""
  End If

  If objBuildCatalog.Sites.Count > 0 Then
    Wscript.Echo "  Has restrictions on the following sites:"

    For Each objSite in objBuildCatalog.Sites
      Wscript.Echo "    " & objSite.Name
    Next
  End If

  Wscript.Echo ""

  If objBuildCatalog.StartPages.Count > 0 Then
    Wscript.Echo "  Has the following start pages:"

    For Each objStartPage in objBuildCatalog.StartPages
      Wscript.Echo "    " & objStartPage.URL
    Next
  End If

  Wscript.Echo ""

  'Compare properties of current build against previous
  Set objCurBldProps = objBuildCatalog.CurrentBuildProperties

  Wscript.Echo "  Current build properties:"

  Wscript.echo "    Build date:            " & objCurBldProps.BuildDate
  Wscript.echo "    # docs:                " _
    & objCurBldProps.NumberOfDocuments 
  Wscript.echo "    Size of index:         " & objCurBldProps.IndexSize _
    & " (MBytes)"
  Wscript.echo "    Size of property store " _
    & objCurBldProps.PropertyStoreSize & " (MBytes)"
  Wscript.echo "    # unique keys:         " _ 
    & objCurBldProps.UniqueKeyCount 
  Wscript.echo "    Crawl number:          " & objCurBldProps.PropSeqNum 
  Wscript.Echo ""

  Set objPrevBldProps = objBuildCatalog.PreviousBuildProperties

  Wscript.Echo "  Previous build properties:"

  Wscript.echo "    Build date:            " & objPrevBldProps.BuildDate
  Wscript.echo "    # docs:                " _
    & objPrevBldProps.NumberOfDocuments 
  Wscript.echo "    Size of index:         " _
    & objPrevBldProps.IndexSize & " (MBytes)"
  Wscript.echo "    Size of property store " _
    & objPrevBldProps.PropertyStoreSize & " (MBytes)"
  Wscript.echo "    # unique keys:         " _ 
    & objPrevBldProps.UniqueKeyCount 
  Wscript.echo "    Crawl number:          " & objPrevBldProps.PropSeqNum 
  Wscript.Echo ""

Next

'Release objects    = Nothing
Set objProtocol     = Nothing
Set objPrevBldProps = Nothing
Set objCurBldProps  = Nothing
Set objStartPage    = Nothing
Set objSite         = Nothing
Set objServer       = Nothing
Set objColumn       = Nothing
Set objBuildCatalog = Nothing 
Set objSearchAdmin  = Nothing 

© 1997-2000 Microsoft Corporation. All rights reserved.