Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Search APIs in Spotlight and Safari

13,093 views

Published on

Published in: Engineering

Search APIs in Spotlight and Safari

  1. 1. Search API in Spotlight and Safari Mercari Inc. @kitasuke
  2. 2. what to index via Search APIs
  3. 3. App results appear in Spotlight and Safari
  4. 4. App results even appear when app not installed
  5. 5. Index Architecture
  6. 6. On-Device index
  7. 7. Apple's cloud index
  8. 8. Cloud index mechanism
  9. 9. Popular public results available to other users • Multiple users engage with device results • Results in Search and Safari (if URL included)
  10. 10. Applebot finds deep links from the web
  11. 11. Ranking system • URL Popularity • Activities • Engagements • Descriptive Results • UI Behavior
  12. 12. 3 Search APIs
  13. 13. NSUserActivity
  14. 14. 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
  15. 15. NSUserActivity API Enable Capabilities var eligibleForHandoff: Bool var eligibleForSearch: Bool var eligibleForPublicIndexing: Bool
  16. 16. NSUserActivity API Provide Attributes and Keywords var title: String? var keywords: Set<String> var contentAttributeSet: CSSearchableItemAttributeSet? var expirationDate: NSDate
  17. 17. NSUserActivity API Restoring on the Web var webpageURL: NSURL?
  18. 18. Create Activity var activity: NSUserActivity = NSUserActivity(activityType: "com.example") activity.title = "Baked Potato Chips" activity.userInfo = ["id": "http://www.example.com/recipe/111"] activity.eligibleForSearch = true activity.eligibleForPublicIndexing = true activity.becomeCurrent()
  19. 19. Continue Activity UIApplicationDelegate func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == "com.example" { // Restore state for userActivity and userInfo } return true }
  20. 20. Public vs Private • Privacy • User-specific activities
  21. 21. Additional Benefits
  22. 22. Handoff
  23. 23. Siri suggestions
  24. 24. CoreSpotlight
  25. 25. CoreSpotlight • For any app content • Methods to add, update and delete items • Used by Messages, Mail, Calendar and Notes
  26. 26. CoreSpotlight
  27. 27. Create Item // Create attributeSet and populate with metadata let 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 items let item = CSSearchableItem(UniqueIdentifier: "1", domainIdentifier: "album-1", attributeSet: attributeSet) // Index item CSSearchableIndex.defaultSearchableIndex().indexSearchableItems([item]) { error in if error != nil { print(error?.localizedDescription) } else { print("Item indexed!") } }
  28. 28. Restore // Application delegate called when CoreSpotlight result is tapped func application(UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: [AnyObject]? -> Void) -> Bool { if userActivity.activityType == CSSearchableItemActionType { let UniqueIdentifier = userActivity.userInfo? [CSSearchableItemActivityIdentifier] as? String // Use 'UniqueIdentifier' } }
  29. 29. Update Same method as adding item to index func indexSearchableItems(items: [CSSearchableItem], completionHandler: ((NSError?) -> Void)?)
  30. 30. Delete Identifiers func deleteSearchableItemsWithIdentifiers(identifiers: [String], completionHandler: ((NSError?) -> Void)?) identifiers = ["1", "4", "5"]
  31. 31. Delete DomainIdentifier func deleteSearchableItemsWithDomainIdentifiers(DomainIdentifiers: [String], completionHandler: ((NSError?) -> Void)?) domainIdentifiers = ["domain-2"]
  32. 32. Delete All func deleteAllSearchableItemsWithCompletionHandler(completionHandler: ((NSError?) -> Void)?)
  33. 33. Web Markup
  34. 34. 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
  35. 35. 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)
  36. 36. Smart App Banners if app is not installed <meta name="myApp" content="app-id=123, app-argument=http://example.com/about>
  37. 37. Deep Linking • Universal link https://developer.apple.com/videos/wwdc/2014/? include=101#101 • Custom URL scheme apple://wwdc/2014/?include=101#101
  38. 38. Universal links advantages • Unique • Secure • Flexible • Work seamlessly across app and website
  39. 39. Support Universal Link in your server • Create your "apple-app-site-association" file • Generate an SSL certification • Sign your file • Upload to your server
  40. 40. Support Universal Link in your app func application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]!) -> Void) -> Bool var webpageURL: NSURL? var activityType: String let NSUserActivityTypeBrowsingWeb: String class NSURLComponents: NSObject
  41. 41. Configure your associated domains
  42. 42. 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 }
  43. 43. Achieving Best Results
  44. 44. Rich Results • More engaging to users • Can improve your ranking
  45. 45. Supported schemas • AggregateRating • Offers • PriceRange • InteractionCount • Organization • Recipe • SearchAction
  46. 46. Actions • Dialing a phone number • Getting directions to an address • Playing audio or video
  47. 47. Relevance
  48. 48. Linking 3 APIs Use same URL
  49. 49. Linking 2 APIs Use same ID
  50. 50. Descriptive Results
  51. 51. Better satisfaction and engagement • Thumbnail, well-structured description, ratings and actions • Relevant and appealing image • Key information user is looking for
  52. 52. Keywords association • Typical items should have 3 to 5 keywords • Category keywords, e.g. "ticket" or "recipe" • Synonyms or abbreviations for item subject
  53. 53. 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
  54. 54. 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
  55. 55. Summary • Easy-to-adopt APIs • Increase engagement • Better user experience
  56. 56. Reference • Introducing Search APIs • Seamless Linking to Your App • iOS Search API Best Practices and FAQs • iOS9 Release Notes

×