SearchAPI是什么
iOS 9.0 系統(tǒng)以后,下拉屏幕或者向右滑到最后會顯示"spotlight"頁面(不支持以下可以升級到iOS9的設(shè)備:iPhone 4S,iPad 2女仰,iPad第三代咏闪,iPad mini, iPod touch第5代)
在搜索欄中搜索關(guān)鍵詞钞速,會顯示不同app的內(nèi)容,如圖一
點擊『豆瓣』一欄里的第一行毫胜,直接跳入了『豆瓣』app箕憾,顯示了『荒野獵人』的頁面
這就是SearchAPI的一個用法伴栓。
官方文檔App Search Programming Guide中的介紹是
Search in iOS 9 gives people great ways to access information inside of your app, even when it isn’t installed. When you make your content searchable, users can access activities and content deep within your app through Spotlight and Safari search results, Handoff, Siri Suggestions, and Reminders. Making your content searchable helps you enhance the user experience of your app and improve its discoverability.
iOS 9 的搜索功能為人們獲取app中的信息提供了極大的便利伦连,即便是在該app并未安裝的情況下。 當(dāng)你的app中的內(nèi)容標(biāo)記為可搜索時钳垮,用戶可以通過Spotlight惑淳,Safari,Handoff扔枫,Siri Suggestion 汛聚,Reminders來獲取到這些頁面和內(nèi)容。讓你的app的內(nèi)容可以被搜索到短荐,這能夠幫助用戶發(fā)現(xiàn)你的app倚舀,并且提升用戶體驗。
App search is easy for you to adopt and customize. You don’t need any prior experience with implementing search, and you control what content gets indexed, which information to show in search results, and where the user goes after tapping a result related to your content.
App search 功能很容易使用和定制忍宋。你自己控制哪些內(nèi)容是被標(biāo)記為可搜索的痕貌,哪些信息是展示在搜索結(jié)果中(spotlight,safari等)糠排,用戶點擊了你的搜索結(jié)果之后頁面跳去哪里舵稠,并不需要在此之前有過implementing search的經(jīng)驗。
iOS 9 中隱私性是一個基本的特征入宦。為了在保護用戶隱私數(shù)據(jù)的情況下給用戶最好的搜索體驗哺徊,這里有兩種索引(index)方式來存儲可被搜索的內(nèi)容。你可以使用各種搜索相關(guān)APIs來對每個item指定合適的索引(index)乾闰,因此落追,明白每種索引(index)是如何工作的就至關(guān)重要。
iOS 9 provides the following indexes:
A private on-device index. Each device contains a private index whose information is never shared with Apple or synced between devices. When you make an item available in a user’s on-device index, only that user can view the item in search results.
Apple’s server-side index. The server-side index stores only publicly available data that you’ve marked appropriately on your website
iOS 9 提供了兩種索引方式:
- 私有的設(shè)備側(cè)索引涯肩。每個設(shè)備包含私有的索引轿钠,被其索引的信息永遠(yuǎn)不會跟Apple共享或者在設(shè)備之間同步。當(dāng)一個條目被標(biāo)記為用戶側(cè)索引病苗,只有該設(shè)備的用戶才能在搜索結(jié)果中看到該類目疗垛。
- Apple 服務(wù)器側(cè)索引。服務(wù)器側(cè)索引只存儲硫朦,你的網(wǎng)站上的贷腕,已經(jīng)恰當(dāng)?shù)臉?biāo)記為公開可見的數(shù)據(jù)。
iOS 9 提供了一些APIs:
- NSUserActivity類中新增了方法和屬性。這些可以幫助你索引用戶在app的活動花履,比如visiting a navigtion point ,創(chuàng)建和查看內(nèi)容芽世。
- Core Spotlight framework。它提供的APIs能把app特定內(nèi)容添加到用戶側(cè)索引诡壁,并且開啟跳入到你的app的deep links。(所謂deep link 指的是點擊spotlight或者safari的搜索結(jié)果荠割,跳進(jìn)你的app中的指定頁面)
- Web markup妹卿。這個能把相關(guān)的web 內(nèi)容可搜索化,幫助你豐富用戶的搜索體驗蔑鹦。
如何選擇合適的APIs夺克?
官方文檔給出了下面的信息。
It’s recommended that all apps use NSUserActivity and that they support Handoff. Using the search-related properties of NSUserActivity is the best way to show users the information they care about and to improve the ranking of your search results. As users perform activities in your app, you use NSUserActivity to add the item to the on-device index. By default, an item represented by an NSUserActivity object is private, which means that it is added to the on-device index. If your content includes activities that all users can view, you identify them as eligible for public indexing. Learn more about using NSUserActivity in Index Activities and Navigation Points.
If your app handles persistent user data, such as documents, photos, and other types of content created by or on behalf of users, use the Core Spotlight APIs to index the content. Unlike NSUserActivity, Core Spotlight does not require users to visit the content in order to index it. In addition, you can use CoreSpotlight APIs to index content at any point, such as when the app loads. Note that Core Spotlight helps you make items searchable in the private on-device index; you don’t use Core Spotlight APIs to make items publicly searchable. Learn more about using Core Spotlight APIs in Index App Content.
If your app hosts some or all of its content on a website, use web markup to let Apple’s web crawler (calledApplebot) index your content in Apple’s server-side index and make it available to all iOS users in Spotlight and Safari search results. Learn more about using web markup to make your web content searchable in Mark Up Web Content. Note that search results generated by web markup are shown in countries that are supported by Spotlight Suggestions.
蘋果推薦所有app 都使用NSUserActivity 來提供Handoff功能嚎朽。使用NSUserActivity中搜索相關(guān)的屬性铺纽,是展示用戶關(guān)心的信息,提升在搜索結(jié)果中的排名的最好的方式哟忍。用戶在你的app中操作的時候狡门,你使用NSUserActivity把當(dāng)前活動增加到用戶側(cè)索引中。默認(rèn)情況下锅很,使用NSUserActivity抽象的條目是私有的其馏,這意味著它被存儲在用戶側(cè)索引中。如果你的內(nèi)容中包括所有用戶都可見的活動爆安,你應(yīng)該把這些內(nèi)容聲明為公開叛复。點擊Index Activities and Navigation Points查看更過關(guān)于如何使用NSUserActivity的信息。
如果你的app操作了持久化的信息扔仓,比如文檔褐奥,圖片,其他類型的(被用戶或者為了用戶創(chuàng)建的)內(nèi)容翘簇,那你應(yīng)該使用Core Spotlight APIs來索引它們撬码。不同于NSUserActivity,Core Spotlight并不要求先讓用戶訪問內(nèi)容才能索引這些缘揪。另外耍群,你可以使用CoreSpotlight APIs在任何節(jié)點索引數(shù)據(jù),比如在app加載的時候找筝。值得注意的是蹈垢,使用Core Spotlight標(biāo)記的數(shù)據(jù)都是用戶側(cè)的,你并不能把item標(biāo)記為公開可搜索的袖裕。點擊Index App Content查看更多關(guān)于使用Core Spotlight APIs的信息曹抬。
如果你的app在網(wǎng)站上托管部分或者全部數(shù)據(jù),使用web markup 可以讓Apple的網(wǎng)頁爬蟲(叫做Applebot)把內(nèi)容索引到Apple服務(wù)器側(cè)急鳄,這使得這些內(nèi)容在所有iOS 用戶的Spotlight 和Safari搜索結(jié)果中都是可見的谤民。請注意:使用web markup生成的搜索結(jié)果會展示在Spotlight Suggestions支持的國家堰酿。
使用NSUserActivity的索引聲明為公開內(nèi)容有什么作用?我在官方文檔里找到這樣一段話
In iOS 9, marking a public item as eligible for public indexing also adds it to the on-device index and confers an additional advantage: When you use web markup to make your related website content searchable, user engagement with publicly eligible search results from your app can help improve the ranking of your website’s content. When a user taps a searchable activity or state in Spotlight search results, you use NSUserActivity APIs to continue the activity and return the user to the relevant area in your app.
在iOS 9中张足,把一條公共類目標(biāo)記為eligibleForPublicIndexing也是存儲到on-device index触创,這給予了更多的功能:當(dāng)你使用web markup技術(shù)把你的相關(guān)網(wǎng)頁內(nèi)容可搜索化時,你的app的公開搜索結(jié)果的用戶參與度为牍,可以幫助你提升你的網(wǎng)頁內(nèi)容的排名哼绑。當(dāng)用戶點擊了spotlight 搜索結(jié)果中的活動或者狀態(tài)時,使用NSUserActivity APIs 幫助用戶繼續(xù)之前的活動碉咆,返回到app中相關(guān)頁面抖韩。
綜合上文,使用NSUserActivity把內(nèi)容標(biāo)記為公開疫铜,可以讓安裝了app的其它用戶搜索到相關(guān)信息茂浮。舉個例子,淘寶電影app壳咕。A用戶訪問了『美人魚』電影頁面席揽,這個時候app內(nèi)部把該(由美人魚電影相關(guān)信息封裝而成)類目標(biāo)記為公開;然后B用戶也執(zhí)行此操作囱井;C用戶驹尼,D用戶...。當(dāng)產(chǎn)生了許多個(未知庞呕,沒公布)相同標(biāo)記之后(每個用戶訪問美人魚頁面在其設(shè)備上生成一個標(biāo)記)新翎,沒有訪問過該頁面的X用戶Y用戶Z用戶在spotlight中搜索『美人魚』,也會出現(xiàn)該搜索結(jié)果(需要用戶安裝淘寶電影app)住练。
隱私
這三種APIs 地啰,跟上文說的兩種索引方式是對應(yīng)的。使用NSUserActivity和Core Spotlight APIs創(chuàng)建的索引都是 on-device index.
使用web markup技術(shù)是存儲在server-side
As the user uses your app, you create activity objects associated with various navigation points and app states. Each item is added to the on-device index by default. In iOS 9, marking a public item as eligible for public indexing also adds it to the on-device index.
The Core Spotlight framework provides ways to index the content within your app and manage the private on-device index.The items you index using Core Spotlight APIs are not added to Apple’s server-side index or synced between devices.
Because items indexed by Applebot are already public, they are stored on Apple’s server-side index.
輔助功能
除了使用NSUserActivity 和 Core Spotlight的APIs讲逛,增加web markup之外亏吝,你還應(yīng)該使用三個關(guān)鍵技術(shù)來給用戶最好的體驗。
Univeral links盏混。 在iOS 9 之后蔚鸥,使用universal links技術(shù),用standard HTTP or HTTPS links取代custom URL schemes许赃。Universal links對所有用戶有有效:如果用戶安裝了你的app止喷,link會把他們引入你的app;如果用戶沒有安裝你的app混聊,lin 會在Safari打開你的網(wǎng)站弹谁。點擊Support Universal Links了解如何使用universal links。
Smart App Banners。當(dāng)用戶在Safari中訪問你的網(wǎng)頁预愤,Smart App Banner 可以讓用戶啟動你的app(如果有安裝)或者有機會下載你的app(如果未安裝)沟于。點擊Promoting Apps with Smart App Banners了解更多關(guān)于Smart App Banners 的信息。
Handoff植康。Handoff 允許用戶從一個設(shè)備切換到另一個設(shè)備時繼續(xù)之前的活動旷太。例如,當(dāng)在Mac瀏覽一個網(wǎng)頁時销睁,在你的iPad上泳秀,會直接進(jìn)入你的原生app中。在iOS 9 中榄攀,Handoff包括了對app search的特殊支持。點擊Handoff Programming Guide了解更多關(guān)于Handoff 的信息金句。
關(guān)于搜索結(jié)果的排名
為了給用戶最好的體驗檩赢,系統(tǒng)會估計用戶使用Spotlight或者Safari搜索跳入app的頻次。正因為如此违寞,那些用戶覺得沒什么用的搜索結(jié)果會很快的被標(biāo)記出來贞瞒,最終不會再搜索結(jié)果中展示。
iOS 會根據(jù)下面的信息來決定搜索結(jié)果展示的順序:
- 用戶通過搜索訪問app內(nèi)容的頻次(only NSUserActivity)
- 用戶通過搜索訪問app的數(shù)量
- 使用web markup標(biāo)記的網(wǎng)頁的訪問量和有效結(jié)構(gòu)化的數(shù)據(jù)量趁曼。
總得來說军浆,你可以通過以下的事情來提供良好的搜索結(jié)果以此鼓勵用戶使用你的app:
- app內(nèi)提供優(yōu)質(zhì)內(nèi)容
- 使用上文提到的搜索APIs來提升搜索結(jié)果與你的app的相關(guān)姓
- 盡可能的只把用戶最喜歡的數(shù)據(jù)供搜索使用
- 必要的情況下通過移除和更新來保持索引的時效性
- 提供切實豐富的搜索信息來引導(dǎo)用戶點擊(搜索結(jié)果)
- 盡可能的減少,用戶點擊搜索結(jié)果到跳入app展示內(nèi)容挡闰,這個過程消耗的時間
點擊 Combine APIs to Increase Coverage andImprove the Ranking of Your Results來了解更多關(guān)于提升用戶搜索體驗的信息
實戰(zhàn)乒融,對幾個app的分析
淘寶電影
對照一臺沒有安裝過淘寶電影app 的iOS 9.2系統(tǒng)的iPhone6Plus,實驗組也是iPhone6Plus正常使用淘寶電影摄悯,訪問頻次2周一次赞季。
試驗過程略
結(jié)果:
1.初次安裝未打開的情況下搜索當(dāng)前上映電影并無結(jié)果。
2.啟動過app奢驯,停留在列表頁申钩,成功收到數(shù)據(jù)后再次搜索,可以搜索出當(dāng)前上映電影瘪阁,即便該并未進(jìn)入過電影詳情撒遣;斷網(wǎng)后依然可搜索。
3.搜索出的結(jié)果管跺,斷網(wǎng)前后并無區(qū)別义黎。
4.半年前的電影,兩臺設(shè)備都無法搜索出伙菜,但是在淘寶電影app內(nèi)搜索出該電影(無論是在app搜索列表或者詳情頁)轩缤,spotlight就可以搜索到。
分析:淘寶電影app會在首頁或者之前,將最近數(shù)據(jù)索引火的。用戶app內(nèi)搜索的結(jié)果和訪問記錄也會被索引壶愤。使用的API應(yīng)該是NSUserActivity,但是是否將屬性設(shè)置為公開馏鹤,并無結(jié)論征椒。
知乎
分析:知乎也是會索引首頁數(shù)據(jù)和用戶訪問記錄。但是經(jīng)過斷網(wǎng)測試湃累,首頁數(shù)據(jù)的緩存可能是隨用戶滑動進(jìn)行勃救,并不是一次性。
百詞斬
分析:百詞斬的app我用的不多治力,但是新下載的app蒙秒,斷網(wǎng)后打開app。然后搜索常用單詞宵统,都可以搜索到晕讲。我懷疑百詞斬是直接使用core spotlight 索引了成千上萬個單詞和常用短語。
關(guān)于Search API的一些使用場景
1.展示對應(yīng)新聞 - 今日頭條
2.展示問答帖子 - 知乎
3.展示電影 - 淘寶電影马澈,豆瓣
4.展示電影院 - 淘寶電影
5.展示單詞 - 百詞斬
6.展示藥品 - 用藥助手
7.展示地標(biāo) - 百度地圖
具體如何使用Search APIs瓢省,就要看需求而定了。
疑惑
- NSUserActivity 設(shè)置為public的情況痊班,在測試(斷網(wǎng)前后對比測試)中并未發(fā)現(xiàn)具體例子勤婚。可能是測試量級較少涤伐。
- 索引數(shù)據(jù)究竟最多能索引多少馒胆?這個我不知道。但是官網(wǎng)上有這樣一句話
Core Spotlight APIs work best when you have no more than a few thousand items.
看樣子废亭,至少幾千個還是運行的妥妥的国章。所以,看需求就放心的使用吧豆村。