Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the basic difference between using NSUserActivity & CoreSpotlight framework for Search programming? How to choose among them?

How to decide which one is most suitable among CoreSpotlight framework & NSUserActivity for Search Programming.

like image 372
Niraj Avatar asked Oct 09 '15 06:10

Niraj


2 Answers

CoreSpotlight

  • does not require users to visit the content in order to index it (index content at any point)
  • private on-device index (you don’t use Core Spotlight APIs to make items publicly searchable)

NSUserActivity

  • can index only as users perform activities in your app
  • public/private indexing
  • indexing navigation points
like image 74
sash Avatar answered Nov 15 '22 05:11

sash


In addition to @sash 's answer, you may want to watch WWDC 2015 Session 709 Introducing App Search

The same

  • userActivity in application(_:continueUserActivity:restorationHandler:) has activityType == CSSearchableItemActionType
  • Utilize CSSearchableItemAttributeSet to describe attribute

The differences

CoreSpotlight

  • Intend for indexing many items, making them searchable
  • Describe attribute with CSSearchableItem.attributeSet
  • batching
  • update, deleting

CoreSpotlight is for private data which is indexed on the device and you can use CoreSpotlight to comprehensively index data in your app.

If you're building or you have a social networking app for instance and you wanted to index all of the messages that the user has sent and received, CoreSpotlight is the right tool for the job.

NSUserActivity

  • Intent for indexing current activity, making it convenient in Spotlight so that we can pick up
  • Describe attribute with contentAttributes
  • Allow content to be in Apple cloud public in eligibleForPublicIndexing

Use NSUserActivity for both public and private content as well as for indexing navigation points inside of your app.

Now there is another flavor of NSUserActivity that Dave touched on which is Public Indexing.

More about NSUserActivity

  • becomeCurrent is for Handoff to start the broadcasting process
  • We may use eligibleForHandoff = false and eligibleForSearch = true to get the nearly same effect as CoreSpotlight
  • We must keep NSUserActivity objects around until the index work finishes
  • We don't know when the index work finishes

Designed to work together

These APIs while distinct, they're really designed to work together.

In the same app for the same content you can adopt multiple APIs.

The only thing to remember is for items that are indexed from multiple places, you want to connect these items by giving them the same ID.

More resources

  • App Search Programming
  • Integrating with iOS System Search
like image 29
onmyway133 Avatar answered Nov 15 '22 05:11

onmyway133