Swift Full Text Search Recommended Solution

偶尔善良 提交于 2019-12-13 06:17:43

问题


I was wondering if there was a recommended solution/library in Swift for integrating full text search (i.e. search bar that filters on presented data as you type, autocomplete)?

I am currently using Firestore as my backend.

Something I've glanced on is Algolia?


回答1:


You can use NSPredicate to search the text inside your objects, like this

let searchString = "test"
var arr:NSArray =
    [["value" : "its a test text to find"],
     ["value" : "another text"],
     ["value" : "find this text"],
     ["value" : "lorem ipsum is a placeholder text commonly"],
     ["value" : "lorem ipsum is a"]]


var pre:NSPredicate = NSPredicate(format: "value CONTAINS[c] %@", searchString)
var result:NSArray = arr.filtered(using: pre) as NSArray

print(result)

it will return a array with the result based on the text that you search




回答2:


Algolia is probably the best solution right now, and is something Firebase themselves recommend. Just a few things to bear in mind is that you'll need a paid for Firebase plan to implement as you'll need a Cloud Function that sends data over to Algolia for indexing.

Once your data is in Algolia there is a great Swift library you can use to implement the Search Bars / Autocompletion you need.



来源:https://stackoverflow.com/questions/49667038/swift-full-text-search-recommended-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!