Swift - IOS - Instant search - Filtering MultiIndex doesn't work

Hello everyone,

hope, you are doing fine. I am using InstantSearch version 7.14 for IOS.
I want make a search on multi indices which basically works. However, in a specific view, I want to provide a filter just to get only few of the results. Here is my code:

private func setupInstantSearchSettings() {
        multiIndexSearcher = .init(appID: ApplicationID(rawValue: APPID), apiKey: APIKey(rawValue: APIKEY), indexNames: ["challenges", "tournament"])
        
        let hitsInteractors: [AnyHitsInteractor] = [
          HitsInteractor<Hit<JSON>>(infiniteScrolling: .on(withOffset: 10), showItemsOnEmptyQuery: true),
          HitsInteractor<Hit<JSON>>(infiniteScrolling: .on(withOffset: 10), showItemsOnEmptyQuery: true),
        ]
        
        multiIndexHitsInteractor = .init(hitsInteractors: hitsInteractors)

        multiIndexHitsInteractor!.connectSearcher(multiIndexSearcher!)
        multiIndexHitsInteractor!.connectController(self)
    }

So, as you can see, I am only doing some initialization in the first step, followed by applying some logic

 private func searchCreatedEvents() {
        addSubview(activityView)
        bringSubviewToFront(activityView)        
        activityView.isHidden = false
                
        challengeFilterState.removeAll()
        tournamentFilterState.removeAll()
    
        multiIndexSearcher!.connectFilterState(challengeFilterState, withQueryAtIndex: 0).disconnect()
        multiIndexSearcher!.connectFilterState(tournamentFilterState, withQueryAtIndex: 1).disconnect()
                
        challengeFilterState = AlgoliaSearch.filterChallenge(indexName: "challenges", filterSelection: filterSelection, userObject: selectedUserObject)
        tournamentFilterState = AlgoliaSearch.filterTournament(indexName: "tournament", filterSelection: filterSelection, userObject: selectedUserObject)
        print(tournamentFilterState)
                            
        multiIndexSearcher!.connectFilterState(challengeFilterState, withQueryAtIndex: 0)
        multiIndexSearcher!.connectFilterState(tournamentFilterState, withQueryAtIndex: 1)
        
        multiIndexSearcher!.query = searchBarController.searchBar.text!
        multiIndexSearcher!.search()
    }

print(tournamentFilterState) shows me **“organizerId”:“fUaaSQN2v0Um89GUSErb9cKShqs2” ** which is correct. According to this filter, I should only get one object from “tournament” collection. But currently, I am getting all the objects back.

Can anyone help me here, please?
Thanks!

Best regards,
Kaan

Hello everyone, do we have any news for this issue? Any ideas @vladislav.fitc ? Thanks a lot!

Hi @kaan548,
Firstly, I’d recommend to update your implementation using the MultiSearcher and multiple HitsSearcher instances as explained in this guide.
The MultiIndexSearcher is now deprecated.
If we go the code you provided, I don’t get the purpose of those lines:

multiIndexSearcher!.connectFilterState(challengeFilterState, withQueryAtIndex: 0).disconnect()
multiIndexSearcher!.connectFilterState(tournamentFilterState, withQueryAtIndex: 1).disconnect()
You connect the filter states and disconnect them right after. Then you reinstantiate filter states (?) and connect them again to the queries. Could you explain it?

Hello @vladislav.fitc , thanks for the reply. I upgraded my algolia version.
To clarify why I have these lines

    multiIndexSearcher!.connectFilterState(challengeFilterState, withQueryAtIndex: 0).disconnect()
    multiIndexSearcher!.connectFilterState(tournamentFilterState, withQueryAtIndex: 1).disconnect()

The function in which I set these properties can be called multiple times. I thought, there might be an issue if I connect the filter states multiple times so I wanted to make sure that only one filter filter state is assigned at a time. However, I couldn’t find how to disconnect the current filter state without assigning it first.

Even if I remove the two lines, the query still doesn’t work as I want to have it. I get all the objects from the collections…