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 9 Developing Java Applications> 9.3 How to Use Java APIs> 9.3.2 Data Searches

9.3.2.4 Setting Maximum Value of Number of Hits

The response performance of sort or aggregation will be stable by setting the maximum value of number of hits. If the number of hits exceeds the maximum value, the sort and aggregation will be terminated, and number of hits corresponding to 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 setHitCountLimit method to set the maximum value of number of hits.

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

[Figure 9-6 The flow when setting maximum value of number of hits]

mark1Sample Code

ShunConnection con = new ShunConnection();

String queryExpression = "/document/base/prefecture == 'Sydney'";
String returnExpression = "/document/base/name, /document/base/price";
String sortExpression = "val(/document/base/price/text()) DESC";
ShunPreparedStatement pstmt = con.prepareSearch(queryExpression, returnExpression);
pstmt.setSort(sortExpression);

/* Set maximum value of number of hits */
pstmt.setHitCountLimit(10000);                                               (1)

ShunResultSet rs = pstmt.executeSearch();

/* Check whether the number of hits exceeds the maximum value */
if (rs.isHitCountLimitOver() ) {                                             (2)
  System.out.println("The number of hits has exceeded the maximum value.");
  System.out.println("[Number of hits] = " + rs.getHitCount());              (3)
}
else {
  System.out.println("[Nunber of hits] = " + rs.getHitCount());
  while(rs.next()) {
   System.out.println("[] = " + rs.getString());
   }
}
rs.close();
pstmt.close();
con.close();

mark2(1) Set maximum value of number of hits

Use the parameter of the setHitCountLimit method to set the maximum value of number of hits.

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

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

Use the isHitCountLimitOver method to check whether the number of hits exceeds the maximum value.

mark2(3) Extract the number of hits

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


Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006