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

Appendix I Sample C++ .NET Programs> I.1 Searching Data

I.1.6 Setting the Maximum Value of Number of Hits

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

mark1An Example of Using the APIs

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

#using <mscorlib.dll>
#using <system.dll>
#using <Fujitsu.Shunsaku.dll>

using namespace System;
using namespace Fujitsu::Shunsaku;

class SampleSearchLimit {
public:
  static void Main( String *args __gc[] ) {
    ShunService *service = 0;

    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
      ShunSearchRequirement *req = 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
      ShunResultSet *rs = service->Search( req );
      // Display the search results
      Console::WriteLine( "Number of hits  = {0}", __box( rs->HitCount ) );
      if ( rs->IsHitCountLimitOver ) {
        Console::WriteLine( "The number of hits has exceeded the limiter of number of hits." );
      }
      int i = 0;
      ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator();
      while ( enumerator->MoveNext() ) {
        ShunRecord *record = enumerator->Current;
        ++i;
        Console::WriteLine( "[Result] Item No. {0} = {1}", __box( i ), record->Data );
      }

      // Close the connection to Shunsaku
      service->Disconnect();

    }
    catch ( ShunContinuousException *e ) {
      // Processing to perform if ShunContinuousException occurs
      try {
        if( service != 0 && 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 );
    }
  }
};

int main() {
  return SampleSearchLimit::Main( Environment::GetCommandLineArgs() );
}

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