algolia / instantsearch-ios

⚡️ A library of widgets and helpers to build instant-search applications on iOS.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/ios/
Apache License 2.0
592 stars 55 forks source link

HighlightedString support in SwiftUI #216

Closed frboulais closed 2 years ago

frboulais commented 2 years ago

Is your feature request related to a problem? Please describe 🙏 Yes, I don't find anyway using highlights in InstantSearch for SwiftUI

Describe the solution you'd like 🤔 Having a [Hit<Item>] getter in HitsInteractor || HitsObservableController so HighlightedString instances can be retrieved for desired fields. Or even better, implement the decoder of HighlightedString so it can be automatically decoded from the Codable Hit model.

Describe alternatives you've considered ✨ Decode the hits by myself from HitsSearcher hits getter ([Hit<JSON>]).

Additional context

VladislavFitz commented 2 years ago

Hi @frboulais ,

I'm not sure if I understood your concern. The Hit is a generic wrapper for any type conforming to Codable protocol. So you can declare your hits interactor as HitsInteractor<Hit<Item>> and connect it to a HitsSearcher. The hits will be properly decoded as a list of Hit<Item> objects, so you can easily access the highlighted values.

By the way, InstantSearch SwiftUI provides a convenient extension for Text to construct a highlighted text view.

frboulais commented 2 years ago

Hey @VladislavFitz ! Thank you very much for your reply! It works exactly as expected! Sorry for this issue and thank you for your great work :) Have a great day!