XML 索引付き成果物の検索

XML 検索索引規則に従って索引付けされた内容を検索するには、検索テキストを elementName[attributeName='attributeValue'] の形式で定義します。 この検索テキストを、RAMAssetQueryBuilder に属性照会フィールドとして追加します。 結果として作成される ArtifactSearchResults によって、具体的な XML の一致項目の結果を取得することができます。 XML データ内で検索を行うための形式の例を以下に示します。
  • 要素のない検索: attributeName='attributeValue'
  • 単一の要素内に定義された複数の属性の検索: elementName[attributeName1='attributeValue1' attributeName2='attributeValue2]
  • パス全体の検索: elementPath1/elementPath2[attributeName='attributeValue']
  • 要素内のテキストの検索: elementName[text()='textValue']
  • XML 文書を検索する場合には、ワイルドカード文字も使用できます: elementName[attributeName='attribute*']
				 //Perform search into XML indexed content
		 		 RAMAssetQueryBuilder query = new RAMAssetQueryBuilder(session);
				 
		 		 //Make sure search within artifacts is on
		 		 query.setSearchModes(SearchQuery.SEARCH_WITHIN_ARTIFACTS_FLAG);
		 		 
		 		 //XML index search text in the form elementName[attributeName='attributeValue']
		 		 String searchText = "wsdl:definitions[targetNamespace='*example*']";
		 		 query.addQueryField(query.QUERY_FIELD_ATTRIBUTE, searchText);
		 		 
		 		 //Perform search
		 		 SearchResult result = session.getAssets(query);
		 		 
		 		 //Get the list of asset matches
		 		 AssetSearchResult[] results = result.getAssetSearchResults();
		 		 
		 		 for(int i = 0; i < results.length; i++){
		 		 		 //For an asset match get the list of artifact matches
		 		 		 ArtifactSearchResult[] artifactMatches = results[i].getMatchingArtifacts();
		 		 		 
		 		 		 for(int j = 0; j < artifactMatches.length; j++){
		 		 		 		 //For an artifact match get the XML index matches
		 		 		 		 String[] xmlIndexMatches = artifactMatches[j].getMatches();
		 		 		 		 
		 		 		 		 for(int k = 0; k < xmlIndexMatches.length; k++){
		 		 		 		 		 System.out.println("Match = " + xmlIndexMatches[k]);
		 		 		 		 }
		 		 		 }
				 }

フィードバック