Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX - |
Contents
Index
![]() ![]() |
Part 2 Developing Applications by APIs | > Chapter 10 Developing .NET Applications | > 10.3 How to Use .NET APIs | > 10.3.2 Data Searches |
Sometimes it is useful to be able to sort the results of a search, using a particular element as a sort key.
To obtain sorted partial information about the data, use the SortExpression property of the ShunSearchRequirement object.
The following diagram shows the process for obtaining data after it has been sorted.
When search results are sorted, the sort process looks up all of the XML documents that match the search conditions. To improve response performance, it is important to narrow down the data to be sorted by specifying a search expression that produces an appropriate number of hits. Set the search conditions in the GetHitCount method to look for the number of XML documents that match the search conditions before the sort process.
ShunService service = new ShunService(); service.Connect(); ShunSearchRequirement req = new ShunSearchRequirement(); (1) req.QueryExpression = "/document/base/prefecture == 'Sydney'"; (1) req.ReturnExpression = "/document/base/name, /document/base/price"; (1) req.SortExpression = "val(/document/base/price/text()) DESC"; (1) ShunResultSet rs = service.Search( req ); (2) Console.WriteLine ( "[Number of hits] = {0}", rs.HitCount ); int i = 0; foreach ( ShunRecord record in rs.Records ) { (3) ++i; Console.WriteLine( "[Result]Item No.{0} = {1}", i, record.Data ); (3) } service.Disconnect(); |
Dim service As New ShunService() service.Connect() Dim req As New ShunSearchRequirement() (1) req.QueryExpression = "/document/base/prefecture == 'Sydney'" (1) req.ReturnExpression = "/document/base/name, /document/base/price" (1) req.SortExpression = "val(/document/base/price/text()) DESC" (1) Dim rs As ShunResultSet = service.Search( req ) (2) Console.WriteLine( "[Number of hits] = {0}", rs.HitCount ) Dim i As Integer = 0 For Each record As ShunRecord In rs.Records (3) i += 1 Console.WriteLine( "[Result] Item No.{0} = {1}", i, record.Data ) (3) Next service.Disconnect() |
Create the ShunSearchRequirement object, and then set the following properties as the search conditions. If the sort process is used, set the sort expression at the SortExpression properties.
Property |
Description |
---|---|
QueryExpression |
Specifies the search expression. This property cannot be omitted. |
ReturnExpression |
Specifies the return expression. |
SortExpression |
Specifies the sort expression. This property can be omitted if the sort process is not used. |
ReplyNumber |
Specifies the reply start number. 1 is specified if it is omitted. |
RequestCount |
Specifies the number of items to return per request. If it is omitted, the number of search results that can be returned will be the same as specifying at the AnsMax in the conductor environment file or the director environment file. |
Refer to Appendix B Format of Search, Return and Sort Expressions for more information on search expressions and return expressions.
Refer to B.5 Sort Expressions for more information on sort expressions.
The total length of the sort keys specified in the sort expression determines the number of data items that can be returned. A maximum of 1,000 items can be returned. No more data can be returned even if a higher value is specified for the reply start number or the number of items to return per request. Use the ReturnableCount property to obtain the maximum number of data items that can be returned.
Appendix C Allowable Values provides a guide to the key lengths and the number of data items that can be returned.
Consecutive data can be extracted by specifying an acquisition start position. This can be used to extract upwards of 1,000 items of data. Refer to 10.3.2.7 Obtaining Consecutive Groups of XML Documents that Match Conditions for details.
For the search, specify and use the ShunSearchRequirement object that the search conditions have been set by the Search method. A ShunResultSet object will be created to hold the results of the search.
Extract 1 record of ShunRecord object from the ShunResultSet object. Then extract the XML documents from the ShunRecord object.
Different properties or methods can be used to extract XML documents for different objectives. The following table shows the properties or methods that can be used.
Property or method |
Function |
---|---|
Data property |
Extracts XML documents as String objects. |
GetDividedData method |
Extracts XML documents as a two-dimensional array of String objects. |
GetStream method |
Extracts XML documents as Stream objects. |
Contents
Index
![]() ![]() |