iosswiftalgoliainstantsearch

Accessing Algolia InstantSearch hits before tableView cellForRow containingHit method


Is it possible to access the hits from InstantSearch query before this
HitsCollectionViewDataSource method?

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath, containing hit: [String : Any]) -> UITableViewCell 

I would like to filter out certain hits before presenting them in the HitsTableWidget.


Solution

  • If you want more customization of your hits, you will have to do more plumbing work and will not be able to use HitsCollectionViewDataSource.

    You should use methods that are available from InstantSearch.shared.searcher, in particular: InstantSearch.shared.searcher.addResultHandler(_:) that will help you specify a closure that will be called everytime new results arrive. What you will have to do is use those search results, filter out the hits that you want, and then manually reload the CollectionView.

    For more info, check our guides here on using InstantSearchCore. If you have any feedback or more questions please don't hesitate!