开发中。
假设你有一份所有朋友有趣的引言列表,你突然想起某个朋友提到过‘疤痕’。不用一个一个地翻阅你的朋友们的引言,试试hit
!只需运行你的数据以获得一个索引
,然后要求它返回谁说的这句话以及它在什么情况下说的。
看看我们的数据
let quotes = [
(string: "Hasta la Pizza, baby", identifier: "Dino"),
(string: "Sorry I'm late, my car aborted half way to work", identifier: "Rob"),
(string: "Icecream always makes me think of Scary Movie. Get it? I scream?", identifier: "Sarah"),
(string: "Who is not been scarred by love has not lived.", identifier: "John")
]
//create an empty index
let index = Index()
//feed it your data
index.updateIndexFromRawStringsAndIdentifiers(quotes, save: false)
我们记得有人对疤痕
说过一些愚蠢的话,让我们试试搜索scar
,希望我们能得到一个匹配。
//search for stuff!
let results = index.prefixSearch("scar")
//look at results
/*
* -> 2 results : [
* "scary" -> [ "Sarah" : Range(34..<39) ],
* "scarred" -> [ "John" : Range(16..<23) ]
* ]
*/
结果有两个。一个来自Sarah关于《Scarlett》电影
Icecream always makes me think of Scary Movie. Get it? I scream?
|---|
34 39
还有一个来自John的,好吧,这是那个愚蠢的回答,你自己看吧
Who is not been scarred by love has not lived.
|-----|
16 23
酷吗?(?)我们的结果实际上告诉我们他使用了范围在16..<23
之间的确切单词scar
red。如果我们想要突出显示这个词 itself,这将很有用。
Honza Dvorsky honzadvorsky.com @czechboy0