Chris
Chris

Reputation: 282

Swift Full Text Search Recommended Solution

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?

Upvotes: 0

Views: 1786

Answers (2)

Chris Edgington
Chris Edgington

Reputation: 3236

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.

Upvotes: 1

ferbass
ferbass

Reputation: 859

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

Upvotes: 1

Related Questions