Indexing thousands of static entries

I would like to integrate the new Search functionality, but have some questions on if what I'm trying to obtain is possible and if so which approach I should take to implement it.


My app has thousands of "entries" that could be searched and revealed in the app. It's basically a database of the same category of things - none of which is tied to a specific user, these are all static and unique entries that can easily be searched using keywords. It's kind of similar to a database of medial conditions. So I want anyone to be able to search for any of them, even if they don't have the app installed. In trying to figure out how to do this, I have a few questions:


  1. Do I use NSUserActivity or the CoreSpotlight API for this? NSUserActivity allows you to specify eligibleForPublicIndexing, but I don't see a description or image property to be able to set - only a title. Also it was mentioned you can't let your activity dealloc, I surely can't hold a reference to thousands of entries. But I don't see any way to make an entry publically searchable using CoreSpotlight, this sounds more like what you would use for user-specific searchable content (like documents they created). Though it does allow adding multiple at once, and you don't need to keep a reference for each item.
  2. This is a scary warning: "Be sure to avoid over-indexing your app content...Because iOS measures the level of user engagement with search results, items that users don’t find useful are quickly identified and can eventually stop showing up in results." This would be very bad for my app. I need all thousands of entries to be searchable, otherwise if some items are missing the search will be unreliable and rendered useless for everyone.
  3. How do you handle localization? There should only be one item indexed for each entry, but the title and description of the item should be localized and searchable. In fact, when I add them all it will use the same unique identifier but the attributeSet will be different depending on the locale the user is in, how does that pan out?


Thanks for any insight and suggestions you can provide!

Accepted Answer

You don't want to put thousands of entries into either NSUserActivity or CoreSpotlight. If I'm understanding what you have, it sounds like this is effectively static content. If that's the case then your best bet would be to have that content be accessible via a website and let the Apple web crawler index it. That would get it into the public index and would allow the content to be served up to all users when they use iOS Search.


NSUserActivity should be used in conjunction with just that, user activity. As the user interacts with your content in the app, it's fine to associate these "entries" with the activity that the user is doing. If you have an identifier per entry you could associate that with the activity (by way of CSSearchableItemAttributeSet's relatedUniqueIdentifier property, where the attribute set is then attached to the NSUserActivity). If you do this as the user is moving around your app then you would use the same activities for handoff (i.e. with eligibleForHandoff = true). You could also generate user activites (perhaps with eligibleForHandoff = false) for things like if the user enters data for a particular entry (I'm envisioning the database of medical conditions where perhaps the user has listed the conditions they are tracking?).


Does that help any? These are good questions to be asking since it's not always immediately obvious what the best way is to integrate your data into these APIs.

Thank you, this is indeed helpful. I will need to do more research in regards to the web crawler and the experience of searching to reveal those results. I'm not sure how users go from the web search result to the native app or how that works - will need to read up on some docs for that.


To better explain my app and answer your question, yes it is purely static content. It is similar to an app that allows you to browse country names and see an image of each country's flag. It seems reasonable you should be able to search with Spotlight to reveal those - it's just a title and an image. In that case there's only hundreds of search results to index, but in my app there's multiple categories, Flags is just one category, so there are ultimately thousands of entries. But it would be very bad if suddenly when you search "Argentina" it doesn't show a flag result for Argentina, but it does show one for "Mexico." Note that there isn't really any activity to continue when using this app. The best I can do is to jump to the appropriate location in the app to reveal what you've searched for.


I already support searching within the app, but would like it to be indexed for searching outside of the app in Spotlight search, or searched even when the app is not installed. Is the web crawler still what you would recommend knowing more about the app and its purpose?

Yes, I would still recommend having the public static information accessible via the web crawler. That will be the way that you would have results surfaced to users who don't have your app installed. You could certainly supplement that by using NSUserActivity and mark items as eligibleForSearch and eligibleForPublicIndexing, although you want to make sure you're also setting a webpageURL on the activity, which matches the related web content.

"You don't want to put thousands of entries into either NSUserActivity or CoreSpotlight. If I'm understanding what you have, it sounds like this is effectively static content."


What about static app content that doesn't have analogous web content? Would the on device CoreSpotlight index be useful or appropriate in that case? Thanks

I just wonder if AppleBot will be notified to crawl the webpage when I create an NSUserActivity and mark items as eligibleForSearch and eligibleForPublicIndexing?

Ex:

- The webpage exemple.com/page1 never been indexed by AppleBot

- I create and retain this NSUserActivity:

let userActivity = NSUserActivity(activityType: "exemple.com.activityType")
self.userActivity.eligibleForHandoff = true
self.userActivity.eligibleForPublicIndexing = true
self.userActivity.eligibleForSearch = true
self.userActivity.title = "Exemple title"
self.userActivity.webpageURL = NSURL.init(string: "http://exemple.com/page1")
self.userActivity.keyworks = keywords

self.userActivity.becomeCurrent

- After "becomeCurrent", does the webpage will be indexed by AppleBot?


Thanks

Indexing thousands of static entries
 
 
Q