0

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
}
Vamsi S
  • 269
  • 3
  • 16
  • Do you get any error ? – Robert D. Mogos Mar 08 '18 at 09:52
  • What is `receivedText` and where is it coming from ? – Robert D. Mogos Mar 08 '18 at 09:53
  • that is my search bar text to filter the data @RobertD.Mogos – Vamsi S Mar 08 '18 at 10:11
  • no i didn't get any error – Vamsi S Mar 08 '18 at 10:12
  • all was fine now after making search from facetfilters i got the data in the query function which was required response that i need to pass to hit to display in collection view that's it but in hit i was getting `_en_products` data which was default whole data from this indices not filtered data @RobertD.Mogos – Vamsi S Mar 08 '18 at 10:15
  • Is it possible to pass the filtered data using facetfilters to hit or not ? @RobertD.Mogos – Vamsi S Mar 08 '18 at 11:35
  • Hi @VamsiS, Are you asking how to access the filters inside the collectionView delegate method, or are you having problems getting the filters to work? – Guy Daher Mar 08 '18 at 15:33
  • I had passed the selected category id's and got response in selected function shown below `InstantSearch.shared.searcher.index.search(query, requestOptions: nil, completionHandler: { (data, error) in self.lastResults = SearchHits(fromDictionary: data!) print(data) self.listCollectionView.reloadHits() })` but how to pass the `data` in the above function to hit because in hit i am getting default indices data @GuyDaher – Vamsi S Mar 09 '18 at 09:41

0 Answers0