Skip To Content

Search portal content

In this topic

A portal can contain a variety of types of items, including web maps, feature services, text files, and so on. All of these items are represented in ArcGIS Runtime SDK as ArcGISPortalItem objects. You can search a portal using keywords to find items and can filter searches according to the type of content you want to find. You can also search users that belong to a particular portal or organization, the content owned by a user, and so on. Publicly accessible items and groups can be accessed without any authentication, but to find items that are secured, a user with access to the item must be authenticated with the portal. See Access the ArcGIS Platform for more information about authenticating with a portal.

If you want to access a specific portal item, you can do so using it's ID, which is unique for all items in a portal. Portal items are represented in ArcGIS Runtime SDK for .NET using the ArcGISPortalItem class. This class has properties that describe an item, including the type of data it represents. For information about how to access a portal item's data, see Access content.

Search for portal items

ArcGIS for Portal has a full-featured text search engine, and provides the ability to search for items or groups based on structured queries. ArcGIS Runtime SDK for .NET provides several methods for searching content in a portal, each designed for searching different types of items. Some searches, such as for basemaps or featured content, do not require additional parameters. For a more focused search, however, you can provide parameters to narrow your query criteria or to define preferences for the search.

The SearchItemsAsync method on the ArcGISPortal class can be used to find any type of portal item. The method accepts a SearchParameters argument that holds a query expression and other preferences for the search.

The following table describes properties of the SearchParameters class.

PropertyTypeDescription

Limit

int

Gets or sets the maximum number of results to be included in the result set response. The default value is 10 and the maximum allowed value is 100.

QueryString

string

Gets or sets the expression that defines the search criteria.

SortField

string

Gets or sets the name of a field on which to sort results.

SortOrder

QuerySortOrder.Ascending = 0

QuerySortOrder.Descending = 1

Gets or sets the order in which results are sorted (default value is ascending).

StartIndex

int

Gets or sets the index of the first entry in the result set response. The index number is 1-based, and the default value is 1. StartIndex, along with the Limit property can be used to paginate the search results.

The expression used to set the QueryString property can further refine search criteria using specific fields as well. In your query expression, use a property identifier (such as orgid, owner, title, or type), followed by a colon and the value. The following expression, for example, will search for web map items within the portal organization with id 123ABC that match the term Cache.

var searchParams = new Esri.ArcGISRuntime.Portal.SearchParameters("\"Cache\" orgid:\"123ABC\" type:(\"web map\" NOT \"web mapping application\")");

See the ArcGIS Rest API search reference for more information, including the fields available for use in your query expression.

The following example searches ArcGIS Online for web map portal items. The results are limited to a maximum of 20 items and will be sorted in descending order (highest to lowest) on the number of views.

// create the search expression (searchTerm is passed in)
var queryString = string.Format("\"{0}\" type:(\"web map\" NOT \"web mapping application\")", searchTerm);

// create a SearchParameters object, set options
var searchParameters = new Esri.ArcGISRuntime.Portal.SearchParameters()
{
    QueryString = queryString,
    SortField = "numviews",
    SortOrder = QuerySortOrder.Descending,
    Limit = 20
};

// open the portal
var arcGISOnline = await Esri.ArcGISRuntime.Portal.ArcGISPortal.CreateAsync();
                    
// execute the search
var itemSearch = await arcGISOnline.SearchItemsAsync(searchParameters);
results = itemSearch.Results;

ArcGISPortal search methods, such as SearchItemsAsync, SearchGroupsAsync, and SearchUsersAsync allow you to provide an optional CancellationToken argument that gives the user the ability to cancel execution of the search task. See the Asynchronous programming topic for more information about allowing task cancellation.

Search for basemaps

Basemaps are represented in a portal as web maps containing a single basemap layer. The following example returns a collection of portal items from the ArcGIS Online basemap gallery using the SearchBasemapGalleryAsync method. This method can be called without any arguments to return all basemap portal items, or by passing a SearchParameters object to further refine your search.

// get a reference to the portal (ArcGIS Online)
var portal = await Esri.ArcGISRuntime.Portal.ArcGISPortal.CreateAsync();

// search the basemaps
var basemapSearch = await portal.ArcGISPortalInfo.SearchBasemapGalleryAsync();
var results = basemapSearch.Results;

// show the results (portal items) in a list box
this.ResultListBox.ItemsSource = results;

Search for featured content

A portal administrator may decide to highlight specific content for an organization. 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 SearchFeaturedItemsAsync method can be used to get featured ArcGISPortalItem objects. This method can be called without any arguments to return all featured portal items, or by passing a SearchParameters object to further refine your search. The following example returns all featured items for a portal.

private async void SearchFeaturedContent()
{
    // get a reference to the portal (ArcGIS Online)
    var portal = await Esri.ArcGISRuntime.Portal.ArcGISPortal.CreateAsync();

    // search the featured content
    var featuredItemSearch = await portal.ArcGISPortalInfo.SearchFeaturedItemsAsync();
    var results = featuredItemSearch.Results;

    // show the results (portal items) in a list box
    this.ResultListBox.ItemsSource = results;
}

Search for portal users and groups

The same programming pattern described previously for searching portal items can be applied to searches for portal users or groups. Call the SearchUsersAsync or SearchGroupsAsync method on the ArcGISPortal object and pass in the same SearchParameters object to define the query expression and search preferences.

The following example searches for users of the portal with the specified user name. A maximum of 20 results are sorted by account creation date (oldest to newest).

// connect to ArcGIS Online
var portal = await Esri.ArcGISRuntime.Portal.ArcGISPortal.CreateAsync();

// build a query that searches for the specified user
var queryString = string.Format("\"{0}\"", this.UsernameTextBox.Text);

// create a SearchParameters object, set options
var searchParameters = new Esri.ArcGISRuntime.Portal.SearchParameters()
{
    QueryString = queryString,
    SortField = "created",
    SortOrder = QuerySortOrder.Ascending,
    Limit = 20
};
                    
// execute the search
var userSearch = await portal.SearchUsersAsync(searchParameters);
var results = userSearch.Results;

Note:

The fields available in a query expression for users or groups differ from those used for a portal items search. See the ArcGIS Rest API search reference for more information.

More information

The following resources provide more information about working with portal content.

Related topics