Skip To Content

Search the portal

In this topic

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.

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

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.

class MyViewController: NSViewController, 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
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:
    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, 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
let queryString = "title:\"San Francisco\" AND type:\"tile package\" "
//Create the query params object
let queryParams = AGSPortalQueryParams(query: 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 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 Use custom queries section.