Skip To Content

Searching the portal

In this topic

A portal has a full-featured text search engine that 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 following sections describe 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're 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;

Predefined queries

The AGSPortalQueryParams class has a number of convenient methods to construct commonly used queries including the following:

  • Searching for groups based on its owner or a title.
    AGSPortalQueryParams *queryParams = [AGSPortalQueryParams queryParamsForGroupsWithOwner:@"<username>" title:@"<title>"];
  • Searching for all items in a group.
    AGSPortalQueryParams *queryParams = [AGSPortalQueryParams queryParamsForItemsInGroup:@"<group_id>"];
  • Searching for items based on a combination of item type, keyword, or group.
    AGSPortalQueryParams *queryParams = [AGSPortalQueryParams queryParamsForItemsOfType:<type> inGroup:@"<group_id>" withSearchString:@"<search_string>"];

For a complete list of predefined queries, see the API reference documentation for AGSPortalQueryParams.

Custom queries

You can perform complex searches on the portal using custom queries that follow the Lucene query syntax. You can either specify a field or group of fields to search or use the default fields of the item or the group. See the ArcGIS Portal REST API search reference for more information on the fields that 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];

Featured content

A portal may highlight certain items and groups because they're relevant to a majority of users or because they're relevant 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 determines the 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 Custom queries section.

See also