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.6 Setting the Maximum Value of Number of Hits

The following is a sample program using the VB .NET to set the maximum value of number of hits.

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 SampleSearchLimit 

  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 = "DirSvr1"
      service.Port = 33101
      service.Connect()

      '' Create ShunSearchRequirement
      Dim req As ShunSearchRequirement = new ShunSearchRequirement()

      '' Set each type of search conditions
      req.QueryExpression = "/document/base/name = 'Hotel'"
      req.ReturnExpression = "/document/base/name/text(), /document/base/price/text()"
      req.SortExpression = "/document/base/price/text()"
      req.ReplyNumber = 1
      req.RequestCount = 5

      '' Set the limiter of number of hits
      req.HitCountLimit = 5

      '' Specify the search condition and execute the search
      Dim rs As ShunResultSet = service.Search( req )

      '' Display the search results
      Console.WriteLine( "Number of hits  = {0}", rs.HitCount )
      If rs.IsHitCountLimitOver
        Console.WriteLine( "The number of hits has exceeded the limiter of number of hits." )
      End If
      Dim i As Integer = 0
      For Each record As ShunRecord In rs.Records
        i += 1
        Console.WriteLine( "[Result]{0} Item No. = {1}", i, record.Data )
      Next

      '' 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       = 8
The number of hits has exceeded the limiter of number of hits.

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006