Search the portal

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

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

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 search results are available or if any errors occurred during the search, 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 : NSViewController <AGSPortalDelegate>     
   - (void) portal:(AGSPortal*)portal 
     didFindGroups:(AGSPortalQueryResultSet*)resultSet {  
     //process group results
   - (void) portal:(AGSPortal*)portal 
         withError:(NSError*)error {
     //handle or report the error

   - (void) portal:(AGSPortal*)portal 
      didFindItems:(AGSPortalQueryResultSet*)resultSet {  
     //process item results
   - (void) portal:(AGSPortal*)portal 
         withError:(NSError*)error {
     //handle or report the error

Also, assign an instance of your class to the AGSPortal object's delegate property.
portal.delegate = self;

Use predefined queries

The AGSPortalQueryParams class has several convenient methods to construct commonly used queries. These include:

  • 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, refer to the AGSPortalQueryParams API reference documentation.

Use custom queries

You can perform complex searches on the portal using custom queries that follow the Lucene query syntax. You can specify a field or group of fields to search on, or you can use the item's or group's default fields. Refer to the ArcGIS Portal REST API's 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 with 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];

Find featured content

A portal may highlight certain items and groups because they are relevant to the 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 you 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 Use custom queries section.