CoreSpotlight Namespace

Allows applications to add data to the system search index.

Classes

CSCustomAttributeKey

A key that app developers can associate with metadata for an indexable item that can appear in user search results.

CSIndexErrorCodeExtensions

Extension methods for the CoreSpotlight.CSIndexErrorCode enumeration.

CSIndexExtensionRequestHandler

Handler for communication between the application and the index on the device. The app does not need to be running for this communication to occur.

CSLocalizedString

Represents a string-like object that returns a locale-specific version of a string.

CSMailboxKey

Represents keys that identify commonly used mailboxes.

CSPerson

An author or a recipient stored in a CSSearchableItemAttributeSet.

CSSearchableIndex

A search index used by Spotlight.

CSSearchableIndex_CSOptionalBatchingExtension

Extension methods for T:CoreServices.CSSearchableIndex.

CSSearchableIndexDelegate

Delegate object providing members that are called when reindexing the index.

CSSearchableIndexDelegate_Extensions

Extension methods to the ICSSearchableIndexDelegate interface to support all the methods from the CSSearchableIndexDelegate protocol.

CSSearchableItem

A uniquely identifiable, searchable object in a CSSearchableIndex.

CSSearchableItemAttributeSet

Holds the actual content to be indexed for search.

CSSearchQuery

Searches data that the developer has previously indexed with the Core Spotlight API.

CSSearchQueryErrorCodeExtensions

Extension methods for the CoreSpotlight.CSSearchQueryErrorCode enumeration.

Interfaces

ICSSearchableIndexDelegate

Interface representing the required methods (if any) of the protocol CSSearchableIndexDelegate.

Enums

CSFileProtection

Enumerates file protection options in calls to M:CoreSpotlight.CSSearchableIndex.FromName*.

CSIndexErrorCode

Enumerates possible errors associated with using Core Spotlight and searching.

CSSearchQueryErrorCode

Enumerates errors that can occur while running a Core Spotlight query with Start().

Delegates

CSSearchableIndexFetchHandler

Completion handler used in FetchLastClientState(CSSearchableIndex, CSSearchableIndexFetchHandler).

Remarks

Spotlight is the system search technology on iOS and OS X. CoreSpotlight allows developers to add data to the search index. An app about the periodic table, for instance, could index the various elements and bring up the relevant page after a search.

Adding data to Spotlight is done by adding CSSearchableItem objects to the DefaultSearchableIndex:

//Create CSSearchableItems
var dataItems = searchIndexMap.Select (keyValuePair => {
    Guid guid = keyValuePair.Key;
    String data = keyValuePair.Value;
    var attributeSet = new CSSearchableItemAttributeSet (UTType.Text);
    attributeSet.Title = data + " Page";
    attributeSet.ContentDescription = "My app's data relating to " + data;
    attributeSet.TextContent = data;

    var dataItem = new CSSearchableItem (guid.ToString (), "com.xamarin.CoreSpotlight0", attributeSet);
    return dataItem;
});
//Add items to system index
CSSearchableIndex.DefaultSearchableIndex.Index (dataItems.ToArray<CSSearchableItem> (), err => {
    if (err != null) {
        Console.WriteLine (err);
    } else {
        Console.WriteLine ("Indexed items successfully");
    }
});

When the application is launched via a Spotlight search for content, the system calls the ContinueUserActivity method with the ActivityType set to ActionType:

public override bool ContinueUserActivity (UIApplication application, NSUserActivity userActivity, UIApplicationRestorationHandler completionHandler)
{
    if (userActivity.ActivityType == CSSearchableItem.ActionType) {
        var uuid = userActivity.UserInfo.ObjectForKey (CSSearchableItem.ActivityIdentifier);
//... handle Spotlight search for identifier