1

My goal is to filter out hits by schoolID. School users on my app have unique schoolIDs and I want them to be able to search through events that only they created and not see any other school's events. I’ve been wanting to figure this out ever since I got the Algolia implemented into my app and I just can’t wrap my head around it, the concept seems so easy to explain but when i try to implement it, there is literally no change in my search results.

I copied the code that one of the Algolia team members in the community forum replied with, but it still doesn’t filter out the hits by schoolID, I will attach my block of code in the updateSearchResults() method, please point out any mistakes you see in my code, I’ve been gunning to fix this big issue in my app for a while. Thanks in advance.

func updateSearchResults(for searchController: UISearchController) {
let searchBar = searchController.searchBar
let settings = Settings()

    .set(\.searchableAttributes, to: [.default("eventName")])
    .set(\.attributesForFaceting, to: [.filterOnly("schoolID")])
    .set(\.attributesToRetrieve, to: ["*"])

 searchResultsIndex.setSettings(settings) { (result) in
    if case .success(let response) = result {
        print("Response: \(response.wrapped)")
    }
}
getTheSchoolsID { (schoolID) in
    if let id = schoolID {
        let schoolID: String = id
    }
    
    let query = Query(searchBar.searchTextField.text!).set(\.filters, to: "schoolID:\(schoolID)")

    searchResultsIndex.search(query: query) { (result) in
        if case .success(let response) = result {
            print("Query Success!")
        }
    }
}

}

Joe - GMapsBook.com
  • 15,787
  • 4
  • 23
  • 68
dsonawave
  • 137
  • 2
  • 12

0 Answers0