Searching the portal

A portal has a full-featured text search engine and provides the ability search for items or groups based on structured queries.

To search a portal, you first need to construct a query using the AGSPortalQueryParams class. The sections below describe in detail how to use predefined queries or construct custom queries.

You then need to pass the query to methods on the AGSPortal class such as findGroupsWithQueryParams: or findItemsWithQueryParams: to find groups and items matching the query criteria.

AGSPortal *portal = ... ; //The portal to search

AGSPortalQueryParams *queryParam = ... ; //The query criteria

//search for items 
[portal findItemsWithQueryParams:queryParams];

//or, search for groups 
[portal findGroupsWithQueryParams:queryParams];

To be informed when the search results are available or if any errors were encountered during the search, you need to set one of your classes as the delegate of AGSPortal.

To do this, your class must adopt the <AGSPortalDelegate> protocol and implement the relevant methods depending on whether you are searching for items or groups.

@interface MyViewController : UIViewController <AGSPortalDelegate>     
   ... 
   
   - (void) portal:(AGSPortal*)portal 
         operation:(NSOperation*)op 
     didFindGroups:(AGSPortalQueryResultSet*)resultSet {  
     //process group results
   }	    
   
   - (void) portal:(AGSPortal*)portal 
         operation:(NSOperation*)op 
     didFailToFindGroupsForQueryParams:(AGSPortalQueryParams*)queryParams
         withError:(NSError*)error {
     //handle or report the error
   }

   - (void) portal:(AGSPortal*)portal 
         operation:(NSOperation*)op 
      didFindItems:(AGSPortalQueryResultSet*)resultSet {  
     //process item results
   }	    
   
   - (void) portal:(AGSPortal*)portal 
         operation:(NSOperation*)op 
     didFailToFindItemsForQueryParams:(AGSPortalQueryParams*)queryParams
         withError:(NSError*)error {
     //handle or report the error
   }

@end
You must also assign an instance of your class to the AGSPortal object's delegate property.
portal.delegate = self;

Using Predefined Queries

The AGSPortalQueryParams class has a number of convenient methods to construct commonly used queries. These include -

For a complete list of predefined queries, please refer to the API reference documentation for AGSPortalQueryParams

Using Custom Queries

You can perform complex searches on the portal using custom queries which follow the Lucene query syntax. You can either specify a field / group of fields to search on, or you can use the default fields of the item or the group. You should refer to the ArcGIS Portal REST API's search reference for more information on which fields can be searched and how to construct your queries.

The following example shows how to construct a query to search for a Tile Package that has the keyword "San Francisco" in its title :

//Define the query criteria
NSString *queryString = @"title:\"San Francisco\" AND type:\"tile package\" ";

//Create the query params object
AGSPortalQueryParams *queryParams = [[[AGSPortalQueryParams alloc] initWithQuery:queryString limit:10] autorelease];

Finding Featured Content

A portal may highlight certain items and groups because they are relevant to majority of users or because they are relevant due to current events. For example, maps of disaster areas after a hurricane, or groups containing wildlife habitat maps if the portal is predominantly used by biologists.

The portal administrator decides which content to highlight. You can access this content through queries available on the AGSPortalInfo object.

// The portal for which we want to fetch featured content
AGSPortal *portal = ... ;

AGSPortalInfo* portalInfo = portal.portalInfo;

//This is an array of custom queries. Each query will fetch a featured group
NSArray* featuredGroupsQueries  = portalInfo.featuredGroupsQueries;

//This is a custom query. It will fetch a single group that contains featured items
NSString* featuredItemsGroupQuery = portalInfo.featureItemsGroupQuery;
You can use these queries as described above in the Using Custom Queries section.

See Also

5/9/2012