Skip To Content ArcGIS for Developers Sign In Dashboard

Searching the portal

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.

let portal:AGSPortal = ...  //The portal to search
let queryParam:AGSPortalQueryParams = ...  //The query criteria
//search for items
//or, search for groups

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.

class MyViewController: UIViewController, AGSPortalDelegate {

 func portal(portal: AGSPortal!, operation: NSOperation!, didFindGroups resultSet: AGSPortalQueryResultSet!) {
  //process group results
 func portal(portal: AGSPortal!, operation: NSOperation!, didFailToFindGroupsForQueryParams queryParams: AGSPortalQueryParams!, withError error: NSError!) {
  //handle or report the error
 func portal(portal: AGSPortal!, operation: NSOperation!, didFindItems resultSet: AGSPortalQueryResultSet!) {
  //process item results
 func portal(portal: AGSPortal!, operation: NSOperation!, didFailToFindItemsForQueryParams queryParams: AGSPortalQueryParams!, withError error: NSError!) {
  //handle or report the error
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.
    let queryParams = AGSPortalQueryParams(forGroupsWithOwner: "<username>", title: "<title>")
  • Searching for all items in a group.
    let queryParams = AGSPortalQueryParams(forItemsInGroup: "<group_id>")
  • Searching for items based on a combination of item type, keyword, or group.
    let queryParams = AGSPortalQueryParams(forItemsOfType: <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
let queryString = "title:\"San Francisco\" AND type:\"tile package\" "
//Create the query params object
let queryParams = AGSPortalQueryParams(query: queryString, limit: 10)

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
let portal:AGSPortal = ...
let portalInfo = portal.portalInfo
//This is an array of custom queries. Each query will fetch a featured group
let featuredGroupsQueries  = portalInfo.featuredGroupsQueries
//This is a custom query. It will fetch a single group that contains featured items
let featuredItemsGroupQuery = portalInfo.featureItemsGroupQuery
You can use these queries as described above in the Custom queries section.

See also