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

Appendix G Sample C# .NET Programs> G.1 Searching Data

G.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 C# .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 C# .NET.

using System;
using Fujitsu.Shunsaku;

class SampleHitCount {
  static public void Main( string[] args ) {
    ShunService service = null;

    try {
      // Create ShunService
      service = new ShunService();

      // Connect Shunsaku by specifying the host name and port number
      service.Host = "DirSvr1";
      service.Port = 33101;
      service.Connect();

      // Search expression
      string query = "/document {/base/city == 'Sydney' AND /information/date == '2006/07/18'}";

      // Search the number of hits using the search expression
      int hitCount = service.GetHitCount( query );

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

      // Close the connection to Shunsaku 
      service.Disconnect();

    }
    catch ( ShunContinuousException e ) {
      // Processing to perform if ShunContinuousException occurs
      try {
        if( service != null && service.State == ShunConnectionState.Open ) {
          service.Disconnect();
        }
      }
      catch ( ShunException ex ) {
        Console.WriteLine("Error message : {0}", ex.Message );
      }
      Console.WriteLine("Error message : {0}", e.Message );
    }
    catch ( ShunConnectionTerminatedException e ) {
      // Processing to perform if ShunConnectionTerminatedException occurs
      Console.WriteLine("Error message : {0}", e.Message );
    }
  }
}

mark1Execution Results

Number of hits = 3

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006