Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResultingDelegate not working with custom widget when using multiple indices #43

Closed
aleincerto opened this issue Sep 8, 2018 · 3 comments

Comments

@aleincerto
Copy link

Hello,

I have MKMapView extending the ResultingDelegate and implementing the on(results: SearchResults?, error: Error?, userInfo: [String: Any]) method, very similar to https://github.com/algolia/instantsearch-ios-examples/blob/master/Icebnb/Icebnb/MapViewWidget.swift.

I had been using a single index and this seemed to work fine, the on() method would get called after each Algolia search. However, I recently started using multiple indices and now the on() method of my MKMapView is not being called anymore. Looking at the code in InstantSearch.swift it seems like when calling InstantSearch.shared.registerAllWidgets(in: self.view) my custom widget should get added to the ResultingDelegates and thus it should work. What am I missing?

As a workaround I did:
InstantSearch.shared.getSearcher(named: Indeces.MAIN_INDEX)?.addResultHandler(mapView.on(results:error:userInfo:))
InstantSearch.shared.getSearcher(named: Indeces.SORTED_BY_RATING)?.addResultHandler(mapView.on(results:error:userInfo:))

and that seemed to fix my issue. However, shouldn't this happen automatically when registering the widgets?

Thank you

@spinach
Copy link
Contributor

spinach commented Sep 10, 2018

Hey @aleincerto,

Thanks for contacting us. I investigated the above and this is definitely a valid point you're making. What you're trying to do is currently not documented, and we'll make sure to add this soon.

So to answer your question:

The addResultHandler is one way to do it indeed.

In order to do make it work with custom widgets, you need your custom widget to implement the protocol SearchableMultiIndexViewModel, which basically requires you to add a property searcherIds: [SearcherId]. You need to fill this property with the indices that you want the widget to "tune into". When you do so, the on() method should be called for all the indices specified. Note that you'll also need to implement func configure(withSearchers searchers: [Searcher]), but you can leave it empty if you don't need to use the searchers associated to that widget.

Also note that as soon as you're using multi-indexing with InstantSearch, then your custom widget will have to implement SearchableIndexViewModel in case they're targeting only 1 index (what I explained right above is for multiple indices). Here you'll have to add the property searcherId: SearcherId and implement func configure(with searcher: Searcher).

Thanks again for reporting this and let us know if you face any issue.

@aleincerto
Copy link
Author

Thanks a lot for the help! I might come back to you with some other questions later on. This InstantSearch framework is really good, nice stuff that you have going on in here. Keep it up.

@spinach
Copy link
Contributor

spinach commented Sep 12, 2018

Thank you for the nice comment! Make sure to contact us if you face any other issues, we're always looking for feedback and ways to improve the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants