Search APIs in Spotlight and Safari

65
Search API in Spotlight and Safari Mercari Inc. @kitasuke

Transcript of Search APIs in Spotlight and Safari

Search API in Spotlight and Safari

Mercari Inc.@kitasuke

what to index via Search APIs

App results appear in Spotlight and Safari

App results even appear when app not installed

Index Architecture

On-Device index

Apple's cloud index

Cloud index mechanism

Popular public results available to other users

• Multiple users engage with device results• Results in Search and Safari (if URL included)

Applebot finds deep links from the web

Ranking system• URL Popularity

• Activities

• Engagements

• Descriptive Results

• UI Behavior

3 Search APIs

NSUserActivity

NSUserActivity and App Search• Activities can be designated as searchable

• Activities can be designated as public

• Add indexable metadata

• Results in iOS Search and Safari

• Revisit activity on Search selection

NSUserActivity APIEnable Capabilitiesvar eligibleForHandoff: Boolvar eligibleForSearch: Boolvar eligibleForPublicIndexing: Bool

NSUserActivity APIProvide Attributes and Keywordsvar title: String?var keywords: Set<String>var contentAttributeSet: CSSearchableItemAttributeSet?var expirationDate: NSDate

NSUserActivity APIRestoring on the Web

var webpageURL: NSURL?

Create Activityvar activity: NSUserActivity = NSUserActivity(activityType: "com.example")

activity.title = "Baked Potato Chips"activity.userInfo = ["id": "http://www.example.com/recipe/111"]

activity.eligibleForSearch = trueactivity.eligibleForPublicIndexing = trueactivity.becomeCurrent()

Continue ActivityUIApplicationDelegatefunc application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == "com.example" { // Restore state for userActivity and userInfo }

return true}

Public vs Private• Privacy• User-specific activities

Additional Benefits

Handoff

Siri suggestions

CoreSpotlight

CoreSpotlight

• For any app content

• Methods to add, update and delete items

• Used by Messages, Mail, Calendar and Notes

CoreSpotlight

Create Item

// Create attributeSet and populate with metadatalet attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTypeImage as String)

attributeSet.title = "Haleakala Sunrise"attributeSet.contentDescription = "May 12, 2015 Maui, Hawaii"

// Create item with unique identifier, domainIdentifier used to group itemslet item = CSSearchableItem(UniqueIdentifier: "1", domainIdentifier: "album-1", attributeSet: attributeSet)

// Index itemCSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { error in if error != nil { print(error?.localizedDescription) } else { print("Item indexed!") }}

Restore

// Application delegate called when CoreSpotlight result is tappedfunc application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == CSSearchableItemActionType { let UniqueIdentifier = userActivity.userInfo? [CSSearchableItemActivityIdentifier] as? String // Use 'UniqueIdentifier' } }

Update

Same method as adding item to indexfunc indexSearchableItems(items: [CSSearchableItem], completionHandler: ((NSError?) -> Void)?)

Delete

Identifiersfunc deleteSearchableItemsWithIdentifiers(identifiers: [String], completionHandler: ((NSError?) -> Void)?)

identifiers = ["1", "4", "5"]

Delete

DomainIdentifierfunc deleteSearchableItemsWithDomainIdentifiers(DomainIdentifiers: [String], completionHandler: ((NSError?) -> Void)?)

domainIdentifiers = ["domain-2"]

Delete

Allfunc deleteAllSearchableItemsWithCompletionHandler(completionHandler: ((NSError?) -> Void)?)

Web Markup

Indexing Web Content

• The content driving your app may live on the web, not locally inside the app

• Deep linked pages from your app's website are indexed for app search

Enabling app search

1. Allow Apple to discover and index your app's website

2. Ensure your app's website contains markup for mobile deep links

3. Enable deep link handling for your app

4. Add markup for structured data (optional, but highly recommended)

Smart App Banners

if app is not installed<meta name="myApp" content="app-id=123, app-argument=http://example.com/about>

Deep Linking• Universal link

https://developer.apple.com/videos/wwdc/2014/?include=101#101

• Custom URL schemeapple://wwdc/2014/?include=101#101

Universal links advantages

• Unique

• Secure

• Flexible

• Work seamlessly across app and website

Support Universal Link in your server

• Create your "apple-app-site-association" file

• Generate an SSL certification

• Sign your file

• Upload to your server

Support Universal Link in your app

func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool

var webpageURL: NSURL?var activityType: Stringlet NSUserActivityTypeBrowsingWeb: Stringclass NSURLComponents: NSObject

Configure your associated domains

Support Custom URL scheme

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { // In this example, the URL is http://example.com/profile/?123 if let components = NSURLComponents(URL: url, resolvingAgainstBaseURL: true), let path = components.path, let query = components.query { if path == "/profile" { // Pass the profile ID from the URL, to the view controller return profileViewController.loadProfile(query) } } } return false}

Achieving Best Results

Rich Results• More engaging to users

• Can improve your ranking

Supported schemas

• AggregateRating

• Offers

• PriceRange

• InteractionCount

• Organization

• Recipe

• SearchAction

Actions

• Dialing a phone number

• Getting directions to an address

• Playing audio or video

Relevance

Linking 3 APIs

Use same URL

Linking 2 APIs

Use same ID

Descriptive Results

Better satisfaction and engagement

• Thumbnail, well-structured description, ratings and actions

• Relevant and appealing image

• Key information user is looking for

Keywords association

• Typical items should have 3 to 5 keywords

• Category keywords, e.g. "ticket" or "recipe"

• Synonyms or abbreviations for item subject

UI Behavior on App Launch

• Go straight to content, no interstitials or multi-step builds

• Guidelines apply to both app and web links

• Time from result to content is measured and used in ranking

Known Issues• Tapping a Mail message, Maps favorites, Note, or Message

in search results does not open the app on some devices

• When submitting an activity to be searchable with NSUserActivity the metadata (attrituteSet) does not get added to the index

See iOS9 Release Notes for more detail

Summary• Easy-to-adopt APIs

• Increase engagement

• Better user experience

Reference• Introducing Search APIs

• Seamless Linking to Your App

• iOS Search API Best Practices and FAQs

• iOS9 Release Notes