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

Part 2 Developing Applications by APIs> Chapter 10 Developing .NET Applications> 10.3 How to Use .NET APIs> 10.3.2 Data Searches

10.3.2.4 Setting the Maximum Value of Number of Hits

The response performance of the sort or aggregation can be stable by setting the maximum value of number of hits. If the number of hits exceeds the maximum value, the sort or aggregation process will be stopped and the number of hits that match the search condition will be returned.

Add a condition to the search expression and narrow the scope of the search for sort or aggregation to prevent the number of hits exceeding the maximum value.

Use the HitCountLimit properties to set the maximum value of number of hits.

The following diagram shows the flow of setting maximum value of number of hits.

[Figure 10-8 Flow of Setting Maximum Value of Number of Hits]

mark1Sample Code

ShunService service = new ShunService();
service.Connect();

ShunSearchRequirement req = new ShunSearchRequirement();
req.QueryExpression = "/document/base/prefecture == 'Sydney'";
req.ReturnExpression = "/document/base/name, /document/base/price";
req.SortExpression = "val(/document/base/price/text()) DESC";
req.HitCountLimit = 10000;                                                     (1)

ShunResultSet rs = service.Search( req );
if ( rs.IsHitCountLimitOver ) {                                                (2)
  Console.WriteLine ("The number of hits has exceeded the maximum value.");
  Console.WriteLine ("[Numer of hits] = " + rs.HitCount);                      (3)
}
else{
  Console.WriteLine("[Number of hits] = " + rs.HitCount);
  int i = 0; 
  foreach ( ShunRecord record in rs.Records ) {
    ++i; 
    Console.WriteLine( "[Result] Item No.{0} = {1}", i, record.Data );
  }
}

service.Disconnect();

mark2(1) Set the Maximum Value of Number of Hits

Set the maximum value of number of hits at the parameter in HitCountLimit properties.

If the sort expression is not set, the error will occur when executing the Search method.

mark2(2) Check whether the number of hits exceeds the maximum value

Check whether the number of hits exceeds the maximum value at the IsHitCountLimitOver properties.

mark2(3) Extract the number of hits

If the number of hits has exceeded the maximum value, only the number of hits can be extracted.


Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006