To manage the results returned from a search in a remote application, use the IPortalSearchResult interface.
Java
public static void displayResults(IPortalSearchRequest searchRequest, int propertyID) throws SearchException, RemoteException { //execute the search ISearchResponse searchResponse = searchRequest.execute(); //get information about the number of results returned System.out.println("Total matches is " + searchResponse.getTotalCount()); System.out.println("First result is " + searchResponse.getFirstResultIndex()); System.out.println("Number returned is " + searchResponse.getReturnedCount()); //write out any warnings SearchWarning warning = searchResponse.getWarning(); if (null != warning) { if (warning.getCode() == (SearchWarning.PROCESSING_TIMED_OUT.getCode())) { System.out.println("Search Warning: Timed out when processing search request; a partial search result was returned"); } if (warning.getCode == (SearchWarning.TOO_MANY_WILDCARD_EXPANSIONS.getCode()) { System.out.println("Search Warning: A wildcard query, such as \"a*\", matched a large number of patterns, only some of which were used for your search."); } } //make the PortalField based on the property ID (from IPortalSearchRequest.SetFieldsToReturn) Field propField = PortalField.forID(propertyID); //iterate through the results ISearchResultSet resultSet = searchResponse.getResultSet(); IEnumerator results = resultSet.getResults(); while (results.hasMoreElements()) { System.out.println("--------------------------------------------------"); IPortalSearchResult result = (IPortalSearchResult) results.nextElement(); System.out.println("name is " + result.getName()); System.out.println("class id is " + result.getClassID()); System.out.println("created is " + result.getCreated()); System.out.println("excerpt is " + result.getExcerpt()); System.out.println("last modified is " + result.getLastModified()); System.out.println("object id is " + result.getObjectID()); System.out.println("url is " + result.getURL()); System.out.println("icon url is " + result.getIconURL()); System.out.println("rank is " + result.getRank()); //write out the property if the field exists Object value = result.getFieldAsObject(propField); if (null != value) { //use GetFieldAsString because type of field is unknown String propResult = result.GetFieldAsString(propField); System.out.println("property field is " + propResult); } } }
.NET (C#)
public static void DisplayResults(IPortalSearchRequest searchRequest, int propertyID) { //execute the search ISearchResponse searchResponse = searchRequest.Execute(); //get information about the number of results returned Console.WriteLine("Total matches is " + searchResponse.GetTotalCount()); Console.WriteLine("First result is " + searchResponse.GetFirstResultIndex()); Console.WriteLine("Number returned is " + searchResponse.GetReturnedCount()); //write out any warnings SearchWarning warning = searchResponse.GetWarning(); if (null != warning) { if (warning.GetCode().Equals(SearchWarning.PROCESSING_TIMED_OUT.GetCode())) { Console.WriteLine("Search Warning: Timed out when processing search request; a partial search result was returned"); } if (warning.GetCode().Equals(SearchWarning.TOO_MANY_WILDCARD_EXPANSIONS.GetCode()) { Console.WriteLine("Search Warning: A wildcard query, such as \"a*\", matched a large number of patterns, only some of which were used for your search."); } } //make the PortalField based on the property ID (from IPortalSearchRequest.SetFieldsToReturn) Field propField = PortalField.ForID(propertyID); //iterate through the results ISearchResultSet resultSet = searchResponse.GetResultSet(); IEnumerator results = resultSet.GetResults(); while (results.MoveNext()) { Console.WriteLine("--------------------------------------------------"); IPortalSearchResult result = (IPortalSearchResult) results.Current; Console.WriteLine("name is " + result.GetName()); Console.WriteLine("class id is " + result.GetClassID()); Console.WriteLine("created is " + result.GetCreated()); Console.WriteLine("excerpt is " + result.GetExcerpt()); Console.WriteLine("last modified is " + result.GetLastModified()); Console.WriteLine("object id is " + result.GetObjectID()); Console.WriteLine("url is " + result.GetURL()); Console.WriteLine("icon url is " + result.GetIconURL()); Console.WriteLine("rank is " + result.GetRank()); //write out the property if the field exists Object value = result.GetFieldAsObject(propField); if (null != value) { //use GetFieldAsString because type of field is unknown String propResult = result.GetFieldAsString(propField); Console.WriteLine("property field is " + propResult); } } }
.NET (VB)
Public Shared Sub DisplayResults(ByVal searchRequest As IPortalSearchRequest, ByVal propertyID As Int32) //execute the search Dim searchResponse As ISearchResponse = searchRequest.Execute() 'get information about the number of results returned Console.WriteLine("Total matches is "& searchResponse.GetTotalCount()) Console.WriteLine("First result is "& searchResponse.GetFirstResultIndex()) Console.WriteLine("Number returned is "& searchResponse.GetReturnedCount()) 'write out any warnings Dim warning AsSearchWarning = searchResponse.GetWarning() If Notwarning IsNothing Then If (warning.GetCode().Equals(SearchWarning.PROCESSING_TIMED_OUT.GetCode())) Then Console.WriteLine("Search Warning: Timed out when processing search request; a partial search result was returned") End If If (warning.GetCode().Equals(SearchWarning.TOO_MANY_WILDCARD_EXPANSIONS.GetCode())) Then Console.WriteLine("Search Warning: A wildcard query, such as a*, matched a large number of patterns, only some of which were used for your search.") End If End If 'make the PortalField based on the property ID (from IPortalSearchRequest.SetFieldsToReturn) Dim propField As Field = PortalField.ForID(propertyID) 'iterate through the results Dim resultSet AsISearchResultSet = searchResponse.GetResultSet() Dim results AsIEnumerator = resultSet.GetResults() While(results.MoveNext()) Console.WriteLine("--------------------------------------------------") Dim result As IPortalSearchResult = DirectCast(results.Current, IPortalSearchResult) Console.WriteLine("name is " + result.GetName()) Console.WriteLine("class id is " + result.GetClassID()) Console.WriteLine("created is " + result.GetCreated()) Console.WriteLine("excerpt is " + result.GetExcerpt()) Console.WriteLine("last modified is " + result.GetLastModified()) Console.WriteLine("object id is " + result.GetObjectID()) Console.WriteLine("url is " + result.GetURL()) Console.WriteLine("icon url is " + result.GetIconURL()) Console.WriteLine("rank is " + result.GetRank()) 'write out the property if the field exists Dim value As Object = result.GetFieldAsObject(propField) If Not value Is Nothing Then 'use GetFieldAsString because type of field is unknown Dim propResult As String = result.GetFieldAsString(propField) Console.WriteLine("property field is " + propResult) End If End While End Sub