Here I had filtered the data using facetfilters
from given facets
and got data in search query function and the response has been passed to model class shown below and in collection view delegate func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath, containing hit: [String : Any]) -> UICollectionViewCell
hit data which was retrieving was default indices data and filtered data has not got in hit can anyone help me how to pass this data to collection view in swift 3 ?
Below here is my code which already tried
if (self.appId != nil && self.apiKEY != nil && self.Indices != nil) {
InstantSearch.shared.configure(appID: "\(self.appId!)", apiKey: "\(self.apiKEY!)", index: "\(self.Indices!)en_products")
InstantSearch.shared.params.attributesToRetrieve = ["*"]
InstantSearch.shared.registerAllWidgets(in: self.view)
if receivedText != nil {
print(String(describing: receivedText!))
InstantSearch.shared.searchBar(searchBar, textDidChange: receivedText!)
InstantSearch.shared.params.attributesToRetrieve = ["*"]
InstantSearch.shared.registerAllWidgets(in: self.view)
}else {
let query = Query()
query.facets = facetsArray
print(categoriesArray)
query.facetFilters = categoriesArray
query.hitsPerPage = 100
InstantSearch.shared.searcher.index.search(query, requestOptions: nil, completionHandler: { (data, error) in
self.lastResults = SearchHits(fromDictionary: data!)
print(data)
self.listCollectionView.reloadHits()
})
}
hitsCollectionViews = [self.listCollectionView]
ActivityIndicator.stopAnimating()
}
open override func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath,
containing hit: [String : Any]) -> UICollectionViewCell {
// print(hit)
let cell: listItemCollectionViewCell
cell = collectionView.dequeueReusableCell(withReuseIdentifier: "hitCell", for: indexPath) as! listItemCollectionViewCell
cell.listItemLabel.text = hit["name"] as? String
cell.listItemPrice.text = hit["price"] as? String
if let strImage = hit["image_url"] as? String {
let baseUrl = "http:\(strImage)"
cell.listItemImg.contentMode = .scaleAspectFit
cell.listItemImg.kf.indicatorType = .activity
if URL(string: baseUrl) != nil {
let resource = ImageResource(downloadURL: URL(string: baseUrl)!, cacheKey: baseUrl)
cell.listItemImg.kf.setImage(with: resource, placeholder: nil, options: nil, progressBlock: nil, completionHandler: nil)
}
else{
cell.listItemImg.image = #imageLiteral(resourceName: "placeholder")
}
}
cell.wishListButton.addTarget(self, action: #selector(saleTappedButton(sender:)), for: .touchUpInside)
cell.listItemStarRating.starBorderColor = UIColor.lightGray
cell.listItemStarRating.starBorderWidth = 0.5
return cell
}