検索操作において、“I.1.1 検索条件に一致するXML文書の件数を求める”および“I.1.2 検索条件に一致するXML文書を指定した形式で取得する”といった操作を経て、絞り込んだ条件を基に、データすべてを取得することになります。
“I.1.2 検索条件に一致するXML文書を指定した形式で取得する”の操作により得られたホテル名を基に、該当するホテルのデータをすべて取得する例を用いて、C++ .NETの使用例を示します。
「2006年7月18日に大阪で宿泊可能なホテルのうち、あるホテルの詳細情報を取得したい。」
年月日(2006年7月18日)および、場所(大阪)を条件に指定し、検索を実行します。また、ホテルに対応するレコードIDを用いて、詳細情報を取得します。
以下にC++ .NETを使用したプログラミング例を示します。
#using <mscorlib.dll> #using <system.dll> #using <Fujitsu.Shunsaku.dll> using namespace System; using namespace Fujitsu::Shunsaku; class SampleSearchByRecordID { public: static void Main( String *args __gc[] ) { ShunService *service = 0; try { // ShunService の作成 service = new ShunService(); // ホスト名 ポート番号を指定して Shunsaku に接続 service->Host = "DirSvr1"; service->Port = 23101; service->Connect(); // ShunSearchRequirement の作成 ShunSearchRequirement *req = new ShunSearchRequirement(); // 各種検索条件の設定 req->QueryExpression = "/document {/base/prefecture == '大阪' AND /information/date == '2006年07月18日'}"; req->ReturnExpression = "/document/base/name/text()"; req->ReplyNumber = 1; req->RequestCount = 30; // 検索条件を指定して検索を実行 ShunResultSet *rs = service->Search( req ); // 検索結果の表示 Console::WriteLine( "ヒット件数 = {0}", __box( rs->HitCount ) ); // 検索用 ShunRecordCollection を作成 ShunRecordCollection *searchRecords = new ShunRecordCollection(); // 検索条件に該当するレコードを取得 ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator(); while ( enumerator->MoveNext() ) { ShunRecord *record = enumerator->Current; if ( record->Data->Equals( "ホテル1" ) ) { searchRecords->Add( record ); } } // 該当レコードの取得に成功している場合 詳細データを参照 if ( searchRecords->Count > 0 ) { rs = service->SearchByRecordID( searchRecords ); enumerator = rs->Records->GetEnumerator(); while ( enumerator->MoveNext() ) { ShunRecord *record = enumerator->Current; Console::WriteLine( "[詳細] = {0}", record->Data ); } } // Shunsaku から切断 service->Disconnect(); } catch ( ShunContinuousException *e ) { // ShunContinuousExceptionが発生した場合の処理を記述 try { if( service != 0 && service->State == ShunConnectionState::Open ) { service->Disconnect(); } } catch ( ShunException *ex ) { Console::WriteLine( "エラーメッセージ : {0}", ex->Message ); } Console::WriteLine( "エラーメッセージ : {0}", e->Message ); } catch ( ShunConnectionTerminatedException *e ) { // ShunConnectionTerminatedExceptionが発生した場合の処理を記述 Console::WriteLine( "エラーメッセージ : {0}", e->Message ); } } }; int main() { return SampleSearchByRecordID::Main( Environment::GetCommandLineArgs() ); } |
ヒット件数 = 3 [詳細] = <document> <base> <name>ホテル1</name> <prefecture>大阪</prefecture> <address>大阪府大阪市中央区</address> <detail>http://xxxxx.co.jp</detail> <price>9000</price> </base> <information> <date>2006年07月18日</date> </information> <note>バス付 トイレ付 地下鉄 △△駅徒歩02分</note> </document> |