Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
Contents Index PreviousNext

Appendix H Sample VB .NET Programs> H.1 Searching Data

H.1.1 Obtaining the Number of XML Documents that Match Search Conditions

If there is a large amount of data to be searched, a large number of items may match the search conditions. In this case, it is not practical to return all the data items for the user to view. In such cases, it is useful to find out first how many data items match the specified condition.

The example below shows how to use the VB .NET to find out how many hotels match the date and location specified as the search condition.

mark1Search Conditions

'How many hotels in Sydney have a vacancy on 2006/07/18?'Execute a search using the date (2006/07/18) and the location (Sydney) as search conditions.

mark1An Example of Using the APIs

The following is a sample program using the VB .NET.

Imports System

Imports Fujitsu.Shunsaku
Imports System.ComponentModel

Class SampleHitCount

  Shared Public Function Main( ByVal args() As String ) As Integer
    Dim service As ShunService = Nothing

    Try
      '' Create ShunService
      service = new ShunService()

      '' Connect Shunsaku by specifying the host name and port number
      service.Host = "DirSrv1"
      service.Port = 33101
      service.Connect()

      '' Search expression
      Dim query As String = "/document {/base/city == 'Sydney' AND /information/date == '2006/07/18'}"

      '' Search the number of hits using the search expression
      Dim hitCount As Integer = service.GetHitCount( query )

      '' Display the number of hits
      Console.WriteLine( "Number of hits = {0}", hitCount )

      '' Close the connection to Shunsaku
      service.Disconnect()
    
    Catch e As ShunContinuousException
      '' Processing to perform if ShunContinuousException occurs
      Try
        If Not service Is Nothing And service.State = ShunConnectionState.Open Then
          service.Disconnect()
        End If
      Catch ex As ShunException
        Console.WriteLine( "Error message : {0}", ex.Message )
      End Try
      Console.WriteLine( "Error message : {0}", e.Message )
    
    Catch e As ShunConnectionTerminatedException
      '' Processing to perform if ShunConnectionTerminatedException occurs
      Console.WriteLine( "Error message : {0}", e.Message )

    End Try
  End Function
End Class

mark1Execution Results

Number of hits = 3

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006