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.4 Obtaining XML Documents that Match Search Conditions after they have been Sorted

When performing a search, the user sometimes prefers to obtain the search results after they have been sorted according to a specific element.

Specify the date and location in the search conditional expression and obtain the number of hotels that match the conditions and partial information about those hotels.

To show how the C# .NET is used, the following example sorts the extracted data in descending order according to the accommodation rate.

mark1Search Conditions

'I want to know the hotels in Sydney that have a vacancy on 2006/07/18, and I want to sort the hotels in descending order according to the accommodation rate.'

Specify the date (2006/07/18) and the location (Sydney) as search conditions. Also specify the accommodation rate in the sort condition and then execute the search.

mark1An Example of Using the APIs

The following is a sample program using the C# .NET.

using System;
using Fujitsu.Shunsaku;

class SampleSort1 {
  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 = "DirSrv1";
      service.Port = 33101;
      service.Connect();

      // Create ShunSearchRequirement
      ShunSearchRequirement req = new ShunSearchRequirement();
      
      // Set each type of search conditions
      req.QueryExpression = "/document {/base/city == 'Sydney' AND /information/date == '2006/07/18'}";
      req.ReturnExpression = "/document/base/name, /document/base/price";
      req.SortExpression = "/document/base/price/text() DESC";
      req.ReplyNumber = 1;
      req.RequestCount = 30;
      
      // Specify the search condition and execute the search
      ShunResultSet rs = service.Search( req );

      // Display the search results
      Console.WriteLine( "Number of hits  = {0}", rs.HitCount );
      int i = 0;
      foreach ( ShunRecord record in rs.Records ) {
        ++i;
        Console.WriteLine( "[Result] Item No. {0} = {1}", i, record.Data );
      }
      
      // 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
[Result] Item No. 1 = <document><name>Hotel 1</name><price>350</price></document>
[Result] Item No. 2 = <document><name>Hotel 3</name><price>250</price></document>
[Result] Item No. 3 = <document><name>Hotel 2</name><price>150</price></document>

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006